进行RPC调用时发生序列化异常 [英] Serialization Exception while making an RPC call
问题描述
我创建了一个非常基本的应用程序。我只有一个服务类和一个相应的Async类,它只包含Java类型并且没有自定义类。但是我仍然得到了序列化异常。
我的服务类看起来像这样。
public interface MyService extends RemoteService {
public String getName();
public Object getAdditionalDetials(ArrayList< String> ids);
public Date getJoiningDate();
}
我的异步界面看起来像这样
public interface MyServiceAsync {
public void getName(AsyncCallback< String> callback);
public void getAdditionalDetials(ArrayList< String> ids,AsyncCallback< Object> callback);
public void getJoiningDate(AsyncCallback< Date> callback);
}
我知道我犯了一些愚蠢的错误。 b
我很熟悉gwt rpc和序列化机制,但会尝试回答您的问题。 >每当你编写涉及RPC的类时,GWT都会创建一个序列化策略文件
。序列化策略文件包含可被序列化的允许类型的白名单。
在您的服务方法中,您提及并引用的所有类型将自动添加到此列表中if他们实现了 IsSerializable
。在你的情况下,你使用了以下两种方法:
public Date getJoiningDate();
这里使用了 String
和 Date
作为返回类型,因此将它添加到序列化策略文件
中。但在下面的方法中,它们存在一个问题,
public Object getAdditionalDetials(Arraylist< String> ids);
这里您使用了 ArrayList和String
是不是问题,他们将被添加到您的白名单,但问题是你提到返回类型为 Object
。这里GWT编译器不知道要添加到白名单或序列化策略
的类型,因此它不会传递你的RPC调用。解决方案是使用提及的类实现 IsSerializable
,而不是提及类型 Object
的返回类型。
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,
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
.
这篇关于进行RPC调用时发生序列化异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!