Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What changes can make serialized class versions incompatible?

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?

like image 331
CodeFusionMobile Avatar asked Aug 05 '26 22:08

CodeFusionMobile


1 Answers

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.

like image 96
Joonas Pulakka Avatar answered Aug 07 '26 12:08

Joonas Pulakka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!