什么IsSerializable或不在GWT中? [英] what IsSerializable or not in GWT?

查看:195
本文介绍了什么IsSerializable或不在GWT中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

public String uri;

公共字符串标签;

公开日期;
}

我检查了* .gwt.rpc策略,并且该对象不存在含义它不是可序列化的或什么的。

谢谢

解决方案

/ div>

您使用的是哪个版本的GWT?


$ b $ < IsSerializable 界面是GWT的遗迹预1.4。您是否尝试过使用Java标准 java.io.Serializable 标记界面?



请参阅此GWT常见问题解答获取更多信息。



< hr>

根据 GWT序列化文档
$ b


如果满足以下所有条件,则用户定义的类是可序列化的:


  1. 可指定 IsSerializable Serializable ,因为它直接实现了其中一个接口,或者是源自一个超类

  2. 所有非 final ,非 - 瞬态实例字段本身都是可序列化的, li>
  3. 从GWT 1.5开始,它必须有一个默认(零参数)构造函数(带有任何访问修饰符)或根本就没有构造函数。


所以你必须为你的类提供一个无参数构造函数,以便由GWT序列化。


I have this simple object in my GWT project. I cannot send it over the wire. Is it impossible to put a constructor in such a class?

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

I checked the *.gwt.rpc policy and the object is not there meaning it is not serializable or something. How can I know beforehand if it is possible to serialize the object?

Thank you

解决方案

What version of GWT are you using?

The IsSerializable interface is a vestige of GWT pre-1.4. Have you tried using the Java-standard java.io.Serializable marker interface?

See this GWT FAQ for more.


As per the 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.

So you must provide a no-arg constructor for your class to be serializable by GWT.

这篇关于什么IsSerializable或不在GWT中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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