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.?

0

3 Answers 3

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;
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

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..?
@TijoKVarghese implements Serializable what package is it coming from?
@TijoKVarghese can you please show us the line of code causing the error?
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

5 Comments

I actually had this problem before but with GWT
@Bourbon : I tried to serialize my object as specified in the link you have given..But that also not working..Thanks .
Ok... can you please post your code implementation? Here we can't help you more if we can't find what's wrong...
@Bourbon : i had included my code also ..please see the code.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.