如何将类型添加到 GWT 的序列化策略白名单? [英] How do I add a type to GWT's Serialization Policy whitelist?

查看:22
本文介绍了如何将类型添加到 GWT 的序列化策略白名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GWT 的序列化程序对 java.io.Serializable 的支持有限,但出于安全原因,它支持的类型有一个白名单.我找到的文档,例如 这个 FAQ 条目 表示任何要序列化的类型都必须包含在序列化策略白名单中",并且该列表是在编译时生成的,但没有解释编译器如何决定白名单中的内容.

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.

生成的列表包含许多属于标准库的类型,例如 java.lang.Stringjava.util.HashMap.尝试序列化 java.sql.Date 时出现错误,它实现了 Serializable 接口,但不在白名单中.如何将这种类型添加到列表中?

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?

推荐答案

您在服务接口中包含的任何特定类型以及它们引用的任何类型都将自动列入白名单,只要它们实现了 java.io.Serializable,例如:

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);

将导致 ArrayList 和 Date 都包含在白名单中.

Will result in ArrayList and Date both being included on the whitelist.

如果您尝试使用 java.lang.Object 而不是特定类型,则会变得更加棘手:

It gets trickier if you try and use java.lang.Object instead of specific types:

public Object getObjectForString(String str);

因为编译器不知道将什么列入白名单.在这种情况下,如果对象没有在您的服务接口中的任何地方被引用,您必须使用 IsSerializable 接口显式标记它们,否则它不会让您通过 RPC 机制传递它们.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆