Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImmutableCollection declarations for GWT-RPC serialization

My understanding is that DTOs to be serialized for GWT RPC ought to declare their fields of the lowest possible implementation type for performance reasons. For example, one should favor ArrayList over List or Collection, in defiance of the advice we normally receive to the contrary (e.g., Effective Java, Item 52).

With the JDK collections, this is no problem—most of the time, a Map is a HashMap, a Set is a HashSet and a List is an ArrayList. However, I am using Guava's Immutable* collections (e.g., ImmutableList), where I really don't know which implementation I'll end up getting. Do I need to just suck it up and let GWT emulate all of them, or is there any way to do damage control here?

like image 716
Ray Avatar asked Mar 15 '26 01:03

Ray


1 Answers

Right. Just use the most specific type that is part of the API.

Subtypes that are annotated with @GwtCompatible(serializable = true) are serializable over GWT RPC unless otherwise specified (by another @GwtCompatible(serializable = false)). You can safely use Immutable* types as GWT RPC interfaces.

like image 66
Hayward Chan Avatar answered Mar 17 '26 03:03

Hayward Chan