我的 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了解更多。
A user-defined class is serializable if all of the following apply:
- It is assignable to
IsSerializable
orSerializable
, either because it directly implements one of these interfaces or because it derives from a superclass that does- All non-
final
, non-transient
instance fields are themselves serializable, and- 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/