DaveKoelle.com ->  Programming and Usability ->  Persistent Externalization in Java

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

  1. Implement Externalizable.
  2. 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.
  3. 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...