I’m putting this here because it bites me every time I do it. If you’re packaging a set of data into a class to pass to the client side of Google’s web toolkit, there are two things you must do for it to work. One is implement IsSerializable, the other is provide a no-args constructor. So when you get meaningless error messages because you, say, pass an ArrayList containing instances of:
public class MyData {
private String field;
public MyData(String field) {
this.field = field;
}
// accessors below
}
it must instead be:
public class MyData implements IsSerializable {
private String field;
public MyData() {}
public MyData(String field) {
this.field = field;
}
// accessors below
}
This has caused me headaches on a number of occasions. The errors you get if you don’t do this come from deep inside GWT and don’t mention where in your code it broke. I wonder why the Google folks didn’t use Serializable, or make it just work regardless…
(Insert additional grumble here about WordPress dropping leading whitespace off of lines in a <code> block. Anyone know how to avoid this? It makes code look ugly.)
The default constructor, seems be a reflection need, not a Serializable problem.