GWT-RPC and immutable transfer objects

GWT-RPC requires that transmission objects to be serialized must have a default constructor (null argument) . Similarly, the final fields will not be serialized (see Question 1054 ).

On the other hand, I know that I have to "minimize variability." My tendency is for my TOs to be immutable, with trailing fields, no default constructor, and no mutators.

How can I use GWT-RPC, adhering to a consistent paradigm as much as possible. Should I convert to a modified object in marshall and then return to immutable? Is it even worth it?

+4
source share
1 answer

Clause 13 in Effective Java (Clause 15 in the second edition) provides strategies to minimize variability or to maintain immutability.

Suppose we remove the mutators, but keep the non-final fields and the default constructor. The effect will be a theoretically volatile object, but practically unchanged. Yes, you can mutate an object a little by using reflection, but just by closing open methods, we can at least prevent its mutation in cases where it is not practical to make the object really unchanged.

+4
source

All Articles