The opposite of this question: How do I add a type to GWT's Serialization Policy whitelist?
GWT is adding undesired types to the serialization policy and bloating my JS. How do I trim my GWT whitelist by hand? Or should I at all?
For example, if I put the interface List on a GWT RPC service class, GWT has to generate Javascript that handles ArrayList, LinkedList, Stack, Vector, … even though my team knows we’re only ever going to return an ArrayList. I could just make the method’s return type ArrayList, but I like relying on an interface rather than a specific implementation. After all, maybe one day we will switch it up and return e.g. a LinkedList. In that case, I’d like to force the GWT serialization policy to compile for only ArrayList and LinkedList. No Stacks or Vectors.
These implicit restrictions have one huge downside I can think of: a new member of the team starts returning Vectors, which will be a runtime error. So besides the question in the title, what is your experience designing around this?
There is a property that can do this class blacklisting. For example, to blacklist non-ArrayList Collections, add these lines to your *.gwt.xml:
This was necessary for me to reduce JS size when sending GWT’s built-in
com.google.gwt.user.client.ui.SuggestOracle$Responseobjects over the wire. Such objects contain a java.util.Collection, but I knew I would only ever be sending back an ArrayList.I still respect the advantages of compile-time checks as discussed in the other responses, comments, and my original question. Indeed, this is a flaky solution if GWT starts picking up additional implementations to serialize (why is this not a whitelist?). However this “rpc.blacklist” property saved me from rolling my own
SuggestOraclejust to get a more specific collection type.