I'm experimenting with the java serialization API to create small persistent objects. In my research I have found a lot on the importance of versioning, so you can detect and handle incompatible changes between the stored object model and the current object model.
What I can't seem to find is what changes to the object model can actually break compatibility. Does removing a primitive member variable break it? Does adding one?
What changes to a Serializable class will cause the readObject/writeObject functions to break down without proper version difference handling?
If you define serialVersionUID
, removing or adding a primitive member doesn't break it (missing primitives get their default values). More info: Java Serialization Specification.
来源:https://stackoverflow.com/questions/4053359/what-changes-can-make-serialized-class-versions-incompatible