What changes can make serialized class versions incompatible?

ぃ、小莉子 提交于 2019-12-01 07:21:05

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!