在 GWT 中既可序列化又可序列化
我在与 GWT 项目分开的项目中有一些 DTO,并且正在尝试将它们用作 GWT 项目内的 DTO。它们实现了可序列化以便与其他服务一起使用。目前,因为我不希望在 GWT RPC 服务接口方法签名中引用它们,所以我必须通过创建不执行任何操作且从不被调用的虚拟方法来“欺骗”GWT 将类列入白名单以进行序列化。
我不想在 GWT 项目中创建单独的 IsSerialized
类以避免重复代码,但虚拟方法也不可取。
我想到的一种替代方案是添加(一个)GWT jar 作为包含我的 DTO 的项目的依赖项,以便它们可以实现 Serialized
和 IsSerialized
。关于“可序列化”和“可序列化”主题的搜索只会引发有关在两者之间进行选择的讨论。
一个类可以同时实现 Serialized
和 IsSerialized
而不会出现复杂情况吗?
I've got some DTOs in a project separate from my GWT project, and am trying to use them as DTOs inside the GWT project. They implement Serializable
for use with another service. Currently, because I do not wish to reference them all in the GWT RPC service interface method signatures, I have to do the technique of "tricking" GWT into whitelisting the classes for serialization by making dummy methods that do nothing and are never called.
I don't want to create separate IsSerializable
classes in the GWT project in order to not duplicate code, but dummy methods aren't desirable either.
One alternative I have thought of would be to add (a) GWT jar(s) as a dependency to the project containing my DTOs so that they may implement both Serializable
and IsSerializable
. Searches on the topic of being both Serializable
and IsSerializable
only brings up discussions on choosing between the two.
Can a class implement both Serializable
and IsSerializable
without complications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是哪个版本的 GWT?如果是最近的(> 1.4),那么据我了解, GWT 文档 说您可以直接使用
Serialized
对象:Which version of GWT are you using? If it's recent (> 1.4) then, as far as I understand, GWT documentation says that you can directly use your
Serializable
objects:我尝试实现 IsSerialized 和 Serialized,因为我希望能够将 DTO 保存到 Http 会话中并通过集群复制它们。我还喜欢允许旧客户端(具有无效策略)能够使用
IsSerialized
提供的新服务(当然是具有相同签名的服务)的想法。但是,当回退到 1.3.3 行为(无有效策略)并且在 DTO 中实现两个接口时,GWT 会变得疯狂(客户端反序列化器尝试实例化一个名为 String content 的类)。一旦我摆脱了Serialized
,GWT RPC 系统就会再次正常工作。编辑:奇怪的是,我在删除
Serialized
并将其放回我的 DTO 后再次尝试。它奏效了。我总是在开发模式下进行测试,也许是插件的错误?I tried implementing both
IsSerializable
andSerializable
, since I want to be able to save my DTOs into Http session and replicate them thru a cluster. Also I like the idea of allowing old clients (with non valid policies) to be able to use the new services (of course the ones with same signature) thatIsSerializable
provides. But GWT goes crazy (the client deserializer tries to instantiate a class named as a String content) when falling back to 1.3.3 behaviour (no valid policy) and having both interfaces implemented in the DTOs. As soon as I get rid ofSerializable
, GWT RPC system works ok again.EDIT: Strangely enough I tried again after removing
Serializable
and put it back in my DTO. And it worked. I was always testing in development mode, maybe a bug with the plugin?