serialization - GWT 中的 IsSerializable 或 NotSerializable 是什么?

标签 serialization gwt gwt-rpc

我的 GWT 项目中有这个简单的对象。我无法通过电线发送它。在这样的类中放一个构造函数是不可能的吗?

public class MceDto implements IsSerializable {
    public MceDto(String uri, String tag) {
        this.uri = uri;
        this.tag = tag;
    }

    public String uri;

    public String tag;

    public Date created;
}

我检查了 *.gwt.rpc 策略,但对象不存在意味着它不可序列化或类似的东西。我如何才能事先知道是否可以序列化对象?

谢谢

最佳答案

您使用的是什么版本的 GWT?

IsSerializable 接口(interface)是 GWT pre-1.4 的遗迹。您是否尝试过使用 Java 标准 java.io.Serializable 标记接口(interface)?

参见 this GWT FAQ了解更多。


根据 GWT serialization docs :

A user-defined class is serializable if all of the following apply:

  1. It is assignable to IsSerializable or Serializable, either because it directly implements one of these interfaces or because it derives from a superclass that does
  2. All non-final, non-transient instance fields are themselves serializable, and
  3. As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all.

因此,您必须为您的类提供一个无参数构造函数,以便 GWT 对其进行序列化。

关于serialization - GWT 中的 IsSerializable 或 NotSerializable 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379313/

相关文章:

java - GSON:如何在保持循环引用的同时防止 StackOverflowError?

java - 继承接口(interface)的 GWT 类生成器

java - GWT 中建议框的建议可以分成单独的组/类别吗?

gwt - GWT 2.3 升级后的 RPC 错误

c++ - 派生类序列化 - 'unregistered class' 异常

python - 如何在 Django 的数据库中存储具有复杂数据字段的 python 对象?

java - 无法运行 GWT ServiceAsync

java - GWT 发送到远程服务器?

将对象序列化到文件时的 C# 最佳实践

java - LibGDX 自动缩放 GWT 窗口以监控分辨率