My recent experiments show that in the JavaLanguage
, binary serialization works rather better than the rumors suggest even after changing and recompiling the source files, provided that we assign a serialVersionUID.
- old (non transient) variables retain their original values
- new or transient variables are assigned to null or zero-like values
- discarded variables are quietly ignored
Just as one might expect.
A good rule of thumb is to assign a serialVersionUID any time we type implements Serializable
I am now more excited about trying ThePrevayler
The consequences of relying upon serialization are still non-trivial,
For the refactoring-addicts (which should be everyone), it means you
need to think very carefully before doing an otherwise trivial activity
like renaming a member variable.
Refactor -> Rename Variable -> Generate Migrator -> Yuck!
Absolutely. Additionally, AnonymousInnerClass
es present a new problem; if we intend to serialize them, we need to maintain the order in which they appear in the containing class. It is probably better to name any class which we intend to serialize.
I am still wary of using JavaSerialization
when you need to make allowance for both
upwards and downwards compatibility.
Explicit serialization and deserialization seems a better approach - for the long term.
OTOH all the data structures I consider serializing are relatively simple directed graphs.