I have a Java class that is stored in an HttpSession object that\'s serialized and transfered between servers in a cluster environment. For the purpose of this explanation,
In some cases you don't have access to the ObjectInputStream, and you can't override readClassDescriptor()
. For example, another subsystem serializes and deserializes these objects. In our case, we had legacy instances serialized in Quartz job data maps.
For this case, you have to maintain a shallow definition of the old class. You can implement the old class's readResolve()
and writeReplace()
methods.
class OldClass{
private int aField;
private Object readResolve() throws ObjectStreamException {
return new NewClass(aField);
}
private Object writeReplace() throws ObjectStreamException {
return new NewClass(aField);
}
}