Strange GWT compiler error when trying to serialize Java objects

I'm currently working on a project on my own where I'm developing a rich client by using the Google Web toolkit and a server using the Spring application framework. The client/server communication is implemented by using the GWT-RPC mechanism. Today however I experienced a strange compilation error when I started to do some experiments in serializing and transferring Java objects (POJOs) to the server. The GWT compiler issued a strange error saying
Type [yourpackagename.classname] was not serializable and has no concrete serializable subtypes.
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.
import java.io.Serializable;

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

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

}
Kindle

Comments

0

Your ad here?