03.11.2010

GWT Serialisation of baseclass

Ups - did you know?
Base classes of Serialisable classes have to be serialisable, too!
Consider:

public abstract class Base {
  private long id;
  public long getId() { return id; }
  public void setName(long id) { this.id=id; }
}
public class Person extends Base 
  implements Serializable {
  private String name;
  public String getName() { return name; }
  public void setName(String name) 
    { this.name=name; }
}
Now transferring Person as a parameter to or result of a standard GWT RPC call would result in id==0 at the receiving side no matter what value it had on the sending side.

This was rather surprising to me but simple to repair:
public abstract class Base 
  implements Serializable {
  ...
}