SerializationException: 类型未包含在可序列化类型集中 [英] SerializationException: type not included in serializable type set
问题描述
在我的 Google Web Toolkit 项目中,出现以下错误:
In my Google Web Toolkit project, I got the following error:
com.google.gwt.user.client.rpc.SerializationException:类型your.class.Type"未包含在可由此 SerializationPolicy 序列化的类型集中,或其 Class 对象无法加载.出于安全考虑,此类型不会被序列化.
com.google.gwt.user.client.rpc.SerializationException: Type ‘your.class.Type’ was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.
此错误的可能原因是什么?
What are the possible causes of this error?
推荐答案
GWT 跟踪一组可以序列化并发送到客户端的类型.your.class.Type
显然不在此列表中.像这样的列表存储在 .gwt.rpc
文件中.这些列表是生成的,因此编辑这些列表可能没有用.这些列表是如何生成的有点不清楚,但您可以尝试以下操作:
GWT keeps track of a set of types which can be serialized and sent to the client. your.class.Type
apparently was not on this list. Lists like this are stored in .gwt.rpc
files. These lists are generated, so editing these lists is probably useless. How these lists are generated is a bit unclear, but you can try the following things:
- 确保
your.class.Type
实现了java.io.Serializable
- 确保
your.class.Type
有一个公共的无参数构造函数 确保
your.class.Type
的成员也这样做
- Make sure
your.class.Type
implementsjava.io.Serializable
- Make sure
your.class.Type
has a public no-args constructor Make sure the members of
your.class.Type
do the same
检查您的程序是否不包含不可序列化类型的集合,例如ArrayList
.如果这样的集合包含 your.class.Type
并被序列化,则会发生此错误.
Check if your program does not contain collections of a non-serializable type, e.g. ArrayList<Object>
. If such a collection contains your.class.Type
and is serialized, this error will occur.
使 your.class.Type
实现 IsSerializable
.这个标记接口专门用于应该发送到客户端的类.这对我不起作用,但我的类也实现了 Serializable
,所以可能两个接口不能很好地协同工作.
Make your.class.Type
implement IsSerializable
. This marker interface was specifically meant for classes that should be sent to the client. This didn't work for me, but my class also implemented Serializable
, so maybe both interfaces don't work well together.
另一种选择是创建一个以 your.class.Type
作为成员的虚拟类,并向您的 RPC 接口添加一个获取和返回虚拟类的方法.这会强制 GWT 编译器将虚拟类及其成员添加到序列化白名单中.
Another option is to create a dummy class with your.class.Type
as a member, and add a method to your RPC interface that gets and returns the dummy. This forces the GWT compiler to add the dummy class and its members to the serialization whitelist.
这篇关于SerializationException: 类型未包含在可序列化类型集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!