My org uses a custom serialization technique, where we store objects iteratively using an output stream. I’m running into the following issue:
Parent and Child classes implement Serializable. Parent class has fields a,b,c, and Child class has e. I added the field d to Parent and updated the parent’s serialization, and now our old clients cannot read the Child serialization code properly. This is because the Child serialization code goes:
OutputStream in = getCurrentOutStream();
current_serialization_num = readVersionNum(in) // The version num is similar to Java's UID and is updated when fields are added.
readParent(in)
e = readField(in)
Since the serialization is done through a DataOutputStream, good XML reader can’t take care of this. I have an ugly solution to this problem, but it won’t extend well at all, so I’d rather not pollute the reader’s mind by introducing it. However, I’d really like to hear how other’s would handle a similar situation.
Objects created by old Parent got serialized by the old serialVersionUID. New objects get serialized by new serialVersionUID.
The way you are implementing that, Child cannot read the old objects as well as the new one at the same time.
You either have to have a same serialVersionUID. If compiler complains put a suppress annotation. You want to clearly communicate compiler it is the same object.