Question

I have created a very basic application. I have only one service class and a corresponding Async class which contains only Java types and no custom classes. But still I get the serialization exception.

My service class looks like this.

public interface MyService extends RemoteService {
  public String getName();
  public Object getAdditionalDetials(ArrayList<String> ids);
  public Date getJoiningDate();
}

My async interface looks like this

public interface MyServiceAsync {
  public void getName(AsyncCallback<String> callback);
  public void getAdditionalDetials(ArrayList<String> ids, AsyncCallback<Object> callback);
  public void getJoiningDate(AsyncCallback<Date> callback);
}

I know I am making some stupid mistake.

Was it helpful?

Solution

I am Naive in gwt rpc and serialization mechanism, but will try to answer your question.

Whenever you write classes involving an RPC, GWT creates a Serialization Policy File. The serialization policy file contains a whitelist of allowed types which may be serialized.

In your Service methods, all the types you mention and refer will be automatically added to this list if they implements IsSerializable. In your case you have used the following two methods,

public String getName();
public Date getJoiningDate();

Here you have used String and Date as your return types and hence it is added to your Serialization Policy File. But in the below method their lies a problem,

public Object getAdditionalDetials(Arraylist<String> ids);

Here you have used ArrayList and String that is not a problem and they will be added to your whitelist, but the problem is you have mentioned return type as Object. Here GWT Compiler does not know what type to be added to whitelist or Serialization Policy and hence it wont pass your RPC call. The solution is use mention a class which implements IsSerializable instead of mentioning the return type of type Object.

OTHER TIPS

FWIW, I was having this problem but my 'Object' type was hidden behind generified classes.

So if one of your rpc methods involves a class:

class Xxx<T> implements IsSerializable {...

It needs to change to:

class Xxx<T extends IsSerializable> implements IsSerializable {...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top