哪些更改可以使序列化类版本不兼容? [英] What changes can make serialized class versions incompatible?
问题描述
我正在尝试使用java序列化API来创建小型持久对象。在我的研究中,我发现了许多关于版本控制的重要性,因此您可以检测并处理存储对象模型与当前对象模型之间的不兼容更改。
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?
对Serializable类进行哪些更改会导致readObject / writeObject函数在没有正确版本差异处理的情况下崩溃?
What changes to a Serializable class will cause the readObject/writeObject functions to break down without proper version difference handling?
推荐答案
如果你定义 serialVersionUID
,删除或添加一个原始成员不会破坏它(缺少原语得到它们默认值)。更多信息: Java序列化规范。
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.
这篇关于哪些更改可以使序列化类版本不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!