Background
I have a class, which has no serialization features overriden, and no serialVersionUID
, but which still is serialized, stored, later deserialized. This is a configuration object, and when changing configuration, data is actually read from configuration UI, then object is created normally "from scratch" and serialized for storage. Only when it is used, object gets created by deserialization.
Now two fields got added to this class, which should not have been serialized, but were... This of course lead to some deserialization problems (NullPointerException when the fields were left null after default deserialization, breaking class invariants), solved by opening configuration UI and saving configuration, thus saving correct serialized form of the object.
Question
Now, what happens in deserialisation of object from saved configuration data, if I modify the class in one of these ways, to do a quick fix:
- remove these fields, and saved data is new version, with these fields in it?
- change these fields to transient, and saved data is new version, with these fields in it?
- change these fields to transient, and saved data is old version, without these fields?
To make this more concrete, let's say the added field is:
private final Map<String, String> extraProperties = new HashMap<String, String>();
And this is either removed from this class, or changed to private final transient
field.
PS. No need to tell me, that custom serialization code should probably be added, and then the whole thing should probably be refactored, to separate persistent and transient data to different classes...