在 GWT 中既可序列化又可序列化

发布于 2024-12-07 02:14:25 字数 468 浏览 0 评论 0原文

我在与 GWT 项目分开的项目中有一些 DTO,并且正在尝试将它们用作 GWT 项目内的 DTO。它们实现了可序列化以便与其他服务一起使用。目前,因为我不希望在 GWT RPC 服务接口方法签名中引用它们,所以我必须通过创建不执行任何操作且从不被调用的虚拟方法来“欺骗”GWT 将类列入白名单以进行序列化。

我不想在 GWT 项目中创建单独的 IsSerialized 类以避免重复代码,但虚拟方法也不可取。

我想到的一种替代方案是添加(一个)GWT jar 作为包含我的 DTO 的项目的依赖项,以便它们可以实现 SerializedIsSerialized 。关于“可序列化”和“可序列化”主题的搜索只会引发有关在两者之间进行选择的讨论。

一个类可以同时实现 SerializedIsSerialized 而不会出现复杂情况吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

您使用的是哪个版本的 GWT?如果是最近的(> 1.4),那么据我了解, GWT 文档 说您可以直接使用 Serialized 对象:

GWT 团队认为社区普遍意识到这些
问题,但更喜欢能够使用该标准的便利性
java.io.Serialized 接口而不是拥有它们的类
实现 isSerialized 标记接口,尽管两个标记
GWT 1.4 支持表示可序列化类的接口
之后。考虑到这一点,GWT团队对GWT RPC进行了更改
系统支持使用java.io.Serialized进行数据传输
将传输的对象(通常称为 DTO)
电线。但是,启用支持有一个条件
新的 GWT RPC 系统中的 java.io.Serializable。

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:

the GWT Team felt that the community was generally aware of these
issues but preferred the convenience of being able to use the standard
java.io.Serializable interface rather than to have their classes
implement the isSerializable marker interface, although both marker
interfaces to denote serializable classes are supported in GWT 1.4 and
later. Considering this, the GWT Team made changes to the GWT RPC
system to support the use of java.io.Serializable for data transfer
objects (commonly referred to as DTOs) that would be transferred over
the wire. However, there is one condition to enable support for
java.io.Serializable in the new GWT RPC system.

灰色世界里的红玫瑰 2024-12-14 02:14:25

我尝试实现 IsSerialized 和 Serialized,因为我希望能够将 DTO 保存到 Http 会话中并通过集群复制它们。我还喜欢允许旧客户端(具有无效策略)能够使用 IsSerialized 提供的新服务(当然是具有相同签名的服务)的想法。但是,当回退到 1.3.3 行为(无有效策略)并且在 DTO 中实现两个接口时,GWT 会变得疯狂(客户端反序列化器尝试实例化一个名为 String content 的类)。一旦我摆脱了 Serialized,GWT RPC 系统就会再次正常工作。

编辑:奇怪的是,我在删除 Serialized 并将其放回我的 DTO 后再次尝试。它奏效了。我总是在开发模式下进行测试,也许是插件的错误?

I tried implementing both IsSerializable and Serializable, 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) that IsSerializable 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 of Serializable, 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文