
Persistent Externalization in Java
Serializing or externalizing Java objects is useful, but making changes to
the member variables of a class can make older serialized objects unusable. Here's a technique
for making externalized objects compatible despite changes to the class.
In a Nutshell
- Implement Externalizable.
- In writeExternal(), create a HashMap, and put the values of your member variables into the HashMap (use whatever keys are easiest for you). Write the HashMap to ObjectOutput.
- In readExternal(), read the HashMap from ObjectInput and pull the values out of the HashMap. Handle cases where a key might not exist - this might be true if you've introduced a new key in later versions of the class.
The Problem
Will write more here...