Strange GWT compiler error when trying to serialize Java objects
2 min read
2 min read
Type [yourpackagename.classname]The error is misleading and strange since my class actually implements the java.io.Serializable interface. By the way GWT doesn't really support the Serializable interface. It has just been introduced after some requests from developers to enable class reusing between applications. Prior to this change, classes had to implement the com.google.gwt.user.client.rpc.IsSerializable interface. I also tried that, with no success.was not serializable and has no concrete serializable subtypes.
import java.io.Serializable;Then I finally found the problem. It seems as if the serialization process needs an empty constructor. After changing my above code into the following, everything worked out fine.
public class ItemLabel implements Serializable {
private String name;
public ItemLabel(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
import java.io.Serializable;
public class ItemLabel implements Serializable {
private String name;
public ItemLabel(){}
public ItemLabel(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}