Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigDecimal does not serialize properly when sending out to as a webrequest. #194

Open
GoogleCodeExporter opened this issue Jul 9, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Send out a BigDecimal to a webservice/wcf server with value = "12.0".
2. If you wish try to create a Marshal for BigDecimal and register with 
SoapEnvelope (Write Method won't get called for some reason, hence Marshaller 
is no use)
3. Inspect the send out value and value type on the wire with wireshark.

What is the expected output? What do you see instead?

I expect to see <Price>12.0</Price> on the output.
I see <Price i:type="d:int">2</Price> instead (NOTE "2" not "12" - incorrect 
value and type(int))

What version of the product are you using? On what operating system?

On the server side I use Win7 WCF basicHttpBinding.
On client side I use Android4.1 
Ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar.

Please provide any additional information below.

I also created a MarshalBigDecimal class and registered it with SoapEnvelope, 
writeInstance() never gets called on it, so i cannot format the output myself.

package paket.android.webservice;

import java.io.IOException;
import java.math.BigDecimal;

import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

public class MarshalBigDecimal implements Marshal {

    public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo expected) throws IOException, XmlPullParserException {
        return new BigDecimal(parser.nextText());
    }

    public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
        writer.text(obj.toString());
    }

    public void register(SoapSerializationEnvelope cm) {
        cm.addMapping(cm.xsd, "decimal", BigDecimal.class, this);
    }

}

ADDITIONAL WEBSERVICE CONTSRUCTION details below (not including whole class)

    public WebServiceWrapper(String soapAction, String methodName, String namespace, String url, boolean isDotNet, int soapEnvelopeVersion, boolean debug) {
        this.mSoap_Action = soapAction;
        this.mMethod_Name = methodName;
        this.mNamespace = namespace;
        this.mUrl = url;
        this.mSoapEnv = new SoapSerializationEnvelope(soapEnvelopeVersion);
        this.mSoapEnv.dotNet = isDotNet;
        this.mRequest = new SoapObject(this.mNamespace, this.mMethod_Name);
        this.mSoapEnv.setOutputSoapObject(this.mRequest);
        this.mAndroidHttpTransport = new HttpTransportSE(this.mUrl, 9000);
        this.mAndroidHttpTransport.debug = debug;
        new MarshalDate().register(mSoapEnv);
        new MarshalFloat().register(mSoapEnv);
        new MarshalBigDecimal().register(mSoapEnv);
        new MarshalDouble().register(mSoapEnv);
        this.mSoapEnv.setAddAdornments(false);
        this.mSoapEnv.implicitTypes = true;
        // Note added soap headers for WSHttpBinding
        this.mSoapEnv.headerOut = WebServiceWrapper.buildHeader(url, soapAction);
        headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));
    }

Original issue reported on code.google.com by [email protected] on 7 Jul 2014 at 4:19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant