You can implement private void readObject(ObjectInputStream in)
in your object class. It kinda "overrides" the default behavior, even though it is declared as "private", so technically it should not. Basically, when java serializer needs to read an object from a stream, of class that has this method implemented, it will call that instead of doing its default thing.
So, you can implement a logic into it, that will read all the existing fields from the stream, and assign default values to those that are missing.
Edit: As @EJP points out (thanks, @EJP!), this does not quite work. You also need to defineprivate static long serialVersionUID
in your class, and set it to the "old" value you see in the exception.
Also, consider replacing Serializable with Externalizable for the future, it gives you some more flexibility, and transparency. Extending Externalizable
tells java that you intend to handle serialization yourself, and it will then not attempt to do its default thing that throws the exception.
In that case, implement readExternal(ObjectInputStream in)
to read members from the stream one-by-one, and initialize those that are missing to some kind of default.