Android error with KSOP2 value Double java.lang.Runtimeexception: Cannot serialize:4.0

Asked

Viewed 291 times

0

Guys I created a webservice Soap in java, I consume and perform operations in various methods, however when I will perform operations passing a double value occurs the following error:

 java.lang.RuntimeException: Cannot serialize: <Valor double>

Follow the complete error:

                E/AndroidRuntime: FATAL EXCEPTION: Thread-1815
                Process: br.com.estudoemvideo, PID: 16300
                java.lang.RuntimeException: Cannot serialize: 4.0
                at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:784)
                at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:764)
                at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:688)
                at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBodyWithAttributes(SoapSerializationEnvelope.java:664)
                at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:777) 
                at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:634)
                at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:205)
                at org.ksoap2.transport.Transport.createRequestData(Transport.java:153)
                at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:149)
                at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
                at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)

I am using the KSOAP2 library to consume the webservice.

  • I solved my problem, but it’s not a solution to the error. I played the webservice data type for String, and in my webservice method I convert from String to double. It worked for me but it’s not the right way to do it.

1 answer

0


I had the same problem and solved using the solution of the link below, I will paste the post here if it stops working.

Basically, after you assemble your envelope, you need to serialize it in order for the process to work properly.

https://stackoverflow.com/a/11718886/3347923

To be Exact use it like this

the Marshal class

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;

import java.io.IOException;


public class MarshalDouble implements Marshal {
  public Object readInstance(XmlPullParser parser, String namespace, String name,
                             PropertyInfo expected) throws IOException, XmlPullParserException {

      return Double.parseDouble(parser.nextText());
  }


  public void register(SoapSerializationEnvelope cm) {
      cm.addMapping(cm.xsd, "double", Double.class, this);

  }


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

the implementation

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(request);

**MarshalDouble md = new MarshalDouble();
md.register(envelope);**

Browser other questions tagged

You are not signed in. Login or sign up in order to post.