4

For some reason I'm stucked with model classes using List as Collection Type and I would like to use the model on the client side. However GWT of course fails serializing java.util.List. However all implementations of List in this model are based on ArrayList. So is it possible to tell GWT to assume List is ArrayList?

Edit GWT fails on compile time, since a possible candidate for List is also java.util.Collections.SingeltonList - which can not be compiled.

I'm using GWT 2.1 and Java 1.6 .

joecks
  • 4,539
  • 37
  • 48
  • A more general question is http://stackoverflow.com/questions/2120142/how-do-i-remove-implementing-types-from-gwts-serialization-policy. – Geoffrey Zheng Jan 05 '13 at 06:22

3 Answers3

3

You can use the GWT-RPC blacklist to prevent GWT from trying to compile certain classes in situations like this. See this issue.

Isaac Truett
  • 8,734
  • 1
  • 29
  • 48
1

GWT RPC should serialize ArrayLists properly since they implement java.io.Serializable. Is it really the list that fails to serialize or the class inside the list?

Another common caveat: did you have include a (required) parameterless constructor in your classes?

KRASH
  • 316
  • 4
  • 5
  • Well yes the constructor is in place. And the List is a ArrayList, which might be a problem on another point. – joecks Dec 21 '10 at 16:49
  • If you only want serialization for GWT, use IsSerializable instead of Serializable. It's an empty marker interface, so it won't mess up with an ORM system like Hibernate. – KRASH Dec 21 '10 at 20:44
1

Gwt creates javascript For every object,and List is more generic type because of this compiler tries generate all features of List , and gwt compiler doesn't know runtime . And GWT's concept of "serializable" is slightly different than serialization based on the standard Java interface Serializable. see the FAQ topic Does the GWT RPC system support the use of java.io.Serializable?

all regarding serialization rules detailed explained here

Jama A.
  • 15,680
  • 10
  • 55
  • 88
  • Well thanks for the hint, but that is not exactly an answer for my question. I have no coice I need to use the model and hence List properties, I just hoped I could be possible to restrict all posible candidates of List o ArrayList. – joecks Dec 21 '10 at 17:03