Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is serialized object compatible in all version of java?

My friend asked me if we serialize an object in java 1.5 and then deserialize it back in java 1.6 then it will throw an exception. What is that exception and why that is thrown?

But i doubt there will be any exception. Reason being nothing is changed in class definition, so it should not face any problem in rebuilding the object back from the serialized form. Am i right? If not, then what and why the exception is thrown?

Note: The class remains untouched not any field, not methods and not serialVersionUID is changed.

like image 530
Rakesh Juyal Avatar asked Sep 11 '25 02:09

Rakesh Juyal


1 Answers

The serialization format has a detailed specification, which is changed only to accomodate new language features (such as enums in Java 5), and I'm pretty sure any such changes are carefully made downwards-compatible.

So unless you encounter a bug (which is certainly possible) or try to deserialize something with a Java version where some features did not exist yet, deserialization should work across different Java versions, vendors and platforms.

like image 121
Michael Borgwardt Avatar answered Sep 13 '25 15:09

Michael Borgwardt