waar19/ksoap2-android

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

GoogleCodeExporter opened this issue · 2 comments

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 yer...@gmail.com on 7 Jul 2014 at 4:19

This ticket should be closed. There is nothing wrong with the library, the 
problem was on my side.

Let this be a lesson to those who forget to add a break; in a switch/case 
statement.
        case 11:
            this.mPrice = new BigDecimal(arg1.toString());
            break; // FORGOT BREAK HERE
        case 12:
            this.mServerId = Integer.parseInt(arg1.toString());
            break;
        case 13:

case 11 (with BigDecimal) had no break, hence case12 was executed right after.

Headache end of a long day, sorry for the needless ticket ;S

Original comment by yer...@gmail.com on 7 Jul 2014 at 4:46

The project is migrating to github. If you believe this issue is still valid 
and should be tracked please file a new issue at 
https://github.com/simpligility/ksoap2-android/issues



Original comment by mosa...@gmail.com on 7 Aug 2015 at 5:35

  • Changed state: AwaitingContribution