The easiest way to do this is to keep the old member variables with their old types and add new member variables for the new types. In addition, you must keep the serialVersionUID of this class the same. then your readObject () implementation can perform any necessary manipulations to convert old data to new data.
Original Object:
public class MyObject { private static final long serialVersionUID = 1234L; private int _someVal; }
A new version:
public class MyObject { private static final long serialVersionUID = 1234L; private int _someVal;
I believe there are more complex options, as well as custom ObjectStreamField[] serialPersistentFields
, ObjectInputStream.GetField
and ObjectOutputStream.PutField
.
source share