0

HI am trying to call a webservice from android application.

Am passing a serializable object Person from my android application to the calling webservice. and at the server side am taking this serializable object and doing some modifications there.

But the problem is while at the time of executing my android app it is showing an exception like: java.lang.RuntimeException: Cannot serialize: com.test.android.Person@43950fe0

Am not getting any idea about solving this. Both sides am using the serializable objects for setting and getting the parameters.

Following is the Person Class am using

public class Person implements Serializable{

private String firstName;
private String lastame;

public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastame() {
    return lastame;
}
public void setLastame(String lastame) {
    this.lastame = lastame;
}

}

my webservice imlpementation class in android side:

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
    request.addProperty("person", person);

    SoapSerializationEnvelope envelope = 
        new SoapSerializationEnvelope(SoapEnvelope.VER11); 

    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    androidHttpTransport.call(SOAP_ACTION, envelope);

    SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;

Am getting the error in this line androidHttpTransport.call(SOAP_ACTION, envelope); if am passing a serializable object as parameter , but if the param is a normal object like String,int etc am not facing any issue.

Can anyone please give me an idea about how to solve this issue.?

TKV
  • 2,533
  • 11
  • 43
  • 56

3 Answers3

1

You have to add a default constructor even if it does nothing. Otherwise it won't be considered as serializable

Code:

public class Person implements Serializable{

    private String firstName;
    private String lastame;

    private Person() {}

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastame() {
        return lastame;
    }
    public void setLastame(String lastame) {
        this.lastame = lastame;
    }
}
Adel Boutros
  • 10,205
  • 7
  • 55
  • 89
  • thanx...but this is also not working..even if am adding the constructor am getting the same error..Cannot serialize: com.test.android.Person@43950fe0. Is our normal serialization as in case with Java will not work in case with Android..? – TKV Jan 13 '12 at 14:56
  • @TijoKVarghese `implements Serializable` what package is it coming from? – Adel Boutros Jan 13 '12 at 15:00
  • @TijoKVarghese can you please show us the line of code causing the error? – Adel Boutros Jan 13 '12 at 15:06
0

Try implementing the KvmSerializable interface here and here are 2 really explicit tutorials hopefully they will help :)

Libathos
  • 3,340
  • 5
  • 36
  • 61
0

If you want to use effectively the serializable interface, it's really important to follow the good way, a good example is shown here : http://www.jondev.net/articles/Android_Serialization_Example_(Java)

It's really important to be rigorous when you implement it.

Good luck! If you want a better response, you need to show more code. Here your class is good to be serialized, but it depends on how you make it!

EDIT : Indeed Adel, good point!

Edit 2 : It seem's to be the same problem as here :

HttpTransportSE requestDump gives NullPointerException

Community
  • 1
  • 1
Bourbon
  • 1,035
  • 7
  • 19