Search code examples
androidweb-servicessoapandroid-ksoap2

java.lang.RuntimeException: Cannot serialize: MyClass


I am trying to consume a web service through my android app by making a call to a function which expects a class object as an input parameter. But while making a call i'm getting an error java.lang.RuntimeException: Cannot serialize: MyClass

I have tried the following solutions but this did not help : KSOAP2 java.lang.RuntimeException: Cannot serialize

https://code.google.com/p/ksoap2-android/issues/detail?id=141

Code: SoapObject request = helperLogin();

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER10);

        envelope.dotNet = false;

        envelope.setOutputSoapObject(request);

        envelope.addMapping(NAMESPACE, "L1UserProfileRowDTO", L1UserProfileRowDTO.class);
        envelope.addMapping(NAMESPACE, "L1UserRowDTO", L1UserRowDTO.class);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        androidHttpTransport.debug = true;
        TextView ACTV = (TextView) findViewById(R.id.textView1);

        androidHttpTransport.call(SOAP_ACTION, envelope);

the last line throws exception.

My class implements serializable interface and also has a default constructor. Please help.


Solution

  • I was able to solve the problem:

    public class L1UserProfileRowDTO extends Vector<String> implements KvmSerializable
    

    and also over ride the following functions:

    @Override
    public Object getProperty(int arg0) {
        // TODO Auto-generated method stub
        return this.get(arg0);
    }
    
    @Override
    public int getPropertyCount() {
        // TODO Auto-generated method stub
        return this.size();
    }
    
    @Override
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
        // TODO Auto-generated method stub
        arg2.name = "string";
        arg2.type = PropertyInfo.STRING_CLASS;
    }
    
    @Override
    public void setProperty(int arg0, Object arg1) {
        // TODO Auto-generated method stub
        this.add(arg1.toString());
    }