Ksoap2 in android cannot serialize

后端 未结 1 478
面向向阳花
面向向阳花 2020-12-20 10:17

I use ksoap2 in android

to send list of numbers as string

But it have error:

java.lang.runtimeexception cannot serialize

I search a solution

相关标签:
1条回答
  • 2020-12-20 11:05

    Use this class for Serialization

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

    Add this line to envelop

        envelope.dotNet = true;
        envelope.implicitTypes = true;
        envelope.encodingStyle = SoapSerializationEnvelope.XSD;
        MarshalDouble md = new MarshalDouble();
        md.register(envelope);
    
    0 讨论(0)
提交回复
热议问题