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.
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,Here you have used
String
andDate
as your return types and hence it is added to yourSerialization Policy File
. But in the below method their lies a problem,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 asObject
. Here GWT Compiler does not know what type to be added towhitelist or Serialization Policy
and hence it wont pass your RPC call. The solution is use mention a class which implementsIsSerializable
instead of mentioning the return type of typeObject
.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:
It needs to change to: