Android bug with KSOP2 with double value java.lang.RuntimeException: Can not serialize: 4.0

0

asked by anonymous 15.10.2016 / 14:54

1 answer

0

I had the same problem and solved using the link solution below, I'll paste the post here in case it stops working.

Basically, after you mount your envelope, you need to serialize it so that the process works correctly.

link

  

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);**
    
17.10.2016 / 16:58