what IsSerializable or not in GWT?

2020-04-17 03:21发布

问题:

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

回答1:

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.