Menu

#14 Zero values of Double cannot be serialized

v1.0 (example)
open
nobody
None
5
2014-11-03
2013-12-16
amwfc
No

Using the following marshal helper:

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());
}

}

and registering it as follows:

    final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.dotNet = true;

    request.addProperty("DblProp", 3.1415);
    envelopeLoc.setOutputSoapObject(request);
    MarshalDouble md = new MarshalDouble();
    md.register(envelope);

    this.httpTransport.call(this.NAMESPACE + this.WEB_METHOD_GETHC, envelope);

The problem arises when 0.0 is used in place of 3.1415 (or any other number for that matter). The web service call stops at the first 0.0 parameter and throws java.lang.Runtime exception 'Cannot serialize: 0.0'.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB