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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With