如何将类型添加到GWT的序列化策略白名单? [英] How do I add a type to GWT's Serialization Policy whitelist?
问题描述
GWT的序列化程序对 java.io.Serializable
支持有限制,但出于安全原因,它有一个它支持的类型的白名单。我找到的文档,例如此常见问题条目表示您想要序列化的任何类型必须包含在序列化策略白名单中,并且该列表在编译时生成,但不能解释编译器如何确定白名单上的内容。
生成的列表包含许多属于标准库的类型,例如 java.lang.String
和的java.util.HashMap
。尝试序列化 java.sql.Date
时出现错误,该错误实现了 Serializable
界面,但未打开白名单。如何将此类型添加到列表中?
您在服务界面中包含的任何特定类型以及它们引用将自动列入白名单,只要它们实现java.io.Serializable,例如:
public String getStringForDates(ArrayList< java .util.Date>日期);
会导致ArrayList和Date都包含在白名单中。
如果尝试使用java.lang.Object而不是特定类型,它会变得更复杂:
public Object getObjectForString(String str);
因为编译器不知道白名单。在这种情况下,如果服务接口中没有引用任何对象,则必须使用IsSerializable接口显式标记它们,否则它将不允许您通过RPC机制传递它们。
GWT's serializer has limited java.io.Serializable
support, but for security reasons there is a whitelist of types it supports. The documentation I've found, for example this FAQ entry says that any types you want to serialize "must be included in the serialization policy whitelist", and that the list is generated at compile time, but doesn't explain how the compiler decides what goes on the whitelist.
The generated list contains a number of types that are part of the standard library, such as java.lang.String
and java.util.HashMap
. I get an error when trying to serialize java.sql.Date
, which implements the Serializable
interface, but is not on the whitelist. How can I add this type to the list?
Any specific types that you include in your service interface and any types that they reference will be automatically whitelisted, as long as they implement java.io.Serializable, eg:
public String getStringForDates(ArrayList<java.util.Date> dates);
Will result in ArrayList and Date both being included on the whitelist.
It gets trickier if you try and use java.lang.Object instead of specific types:
public Object getObjectForString(String str);
Because the compiler doesn't know what to whitelist. In that case if the objects are not referenced anywhere in your service interface, you have to mark them explicitly with the IsSerializable interface, otherwise it won't let you pass them through the RPC mechanism.
这篇关于如何将类型添加到GWT的序列化策略白名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!