Serialization Exception while making an RPC call

痴心易碎 提交于 2019-12-20 04:55:07

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/14303223/serialization-exception-while-making-an-rpc-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!