从 GWT 应用程序中执行 RPC 时出现 SerializationPolicy 错误 [英] SerializationPolicy error when performing RPC from within GWT application

查看:22
本文介绍了从 GWT 应用程序中执行 RPC 时出现 SerializationPolicy 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下异常:

com.google.gwt.user.client.rpc.SerializationException:类型java.lang.Long"未包含在可由此 SerializationPolicy 序列化的类型集中,或其 Class 对象无法加载.出于安全考虑,此类型不会被序列化

com.google.gwt.user.client.rpc.SerializationException: Type 'java.lang.Long' 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

使用 GWT 2.1 和内置的 Jetty 服务器.根据文档,这种类型绝对是可序列化的......我如何将它包含在 SerializationPolicy 中?

using GWT 2.1 and the built in Jetty server. According to the docs, this type is definitely serializable... How can I include it in the SerializationPolicy?

推荐答案

需要在 RPC 服务中包含一个多余的方法,该方法将许多对象列入白名单".这是因为使用了泛型,GWT 无法确定我可能正在序列化哪个对象以包含在某个泛型中.

Needed include a superfluous method in the RPC service that "whitelists" a number of objects. This arises because of the use of generics, GWT is unable to necessarily determine which object I may be serializing to include within some generic.

我包含了所有可能需要(取消)序列化的类型作为对象的成员 (SerializableWhitelist).我向 RPC servlet 对象添加了一个方法,如:

I included all of the types that may need to be (un)serialized as members of an object (SerializableWhitelist). I added a method to the RPC servlet object like:

public SerializableWhitelistjunk(SerializableWhitelist l) { return null;}

值得注意的是,您需要将白名单数据类型作为参数和返回类型包含在内,因为 GWT 显然维护着两个单独的序列化策略.

It's worth noting that you need to include the whitelist datatypes as both an argument and as the return type, as GWT apparently maintains two separate serialization policies.

这篇关于从 GWT 应用程序中执行 RPC 时出现 SerializationPolicy 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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