Passing data to GWT

By | July 21, 2006

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.)

One thought on “Passing data to GWT

  1. Iago

    The default constructor, seems be a reflection need, not a Serializable problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.