sworded
sworded

Reputation: 2499

GWT RPC serializing

I am trying to send over MyClass through RPC, but am getting : Type MyClass was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.For security purposes, this type will not be serialized.

I have looked at GWT - occasional com.google.gwt.user.client.rpc.SerializationException and tried their solution, but it did not work.

The difference is that MyClass is located in another project. The project structure is:

MyApiProject
-contains MyClass
MyClientProject
MyServerProject

I have also tried passing an enum through the RPC from MyApiProject, which also failed.

public class MyClass
    implements Serializable
{
    private static final long serialVersionUID = 5258129039653904120L;

    private String str;

    private MyClass()
    {
    }

    public MyClass(String str)
    {
        this.str = str;
    }

    public String getString()
    {
        return this.str;
    }
}

in the RemoteService I have:

mypackage.MyClass getMyClass();

in the RemoteServiceAsync I have:

void getMyClass(AsyncCallback<mypackage.MyClass> callback);

Upvotes: 2

Views: 4963

Answers (3)

sworded
sworded

Reputation: 2499

I had to change implements Serializable to implements IsSerializable

Upvotes: 6

Paul
Paul

Reputation: 1088

I believe GWT requires an RPC serializable class to also have a public no-argument constructor.

Try removing

   private MyClass()
    {
    }

or set it to

   public MyClass()
    {
    }

Upvotes: 0

Brad Gardner
Brad Gardner

Reputation: 1627

This usually pops up when you are using another type inside of your class that is not serializable. Check the properties of your class and make sure they are all serializable, post the code of MyClass here and I can look at it as well.

Upvotes: 0

Related Questions