0

Is object serialization backwards compatible from Java8 to Java7?

I.e., does the Java serialization specification (http://docs.oracle.com/javase/8/docs/platform/serialization/spec/serialTOC.html) guarantee that the following works: I compile class A into a Java8 application, serialize an object of A (into a file, say) and deserialize that object in a Java7 application (compiled with the same version of class A).

Could somebody point me to the exact part of the specification which specifically adresses different major versions? If there is none, from what part can I deduce said compatibility?

Note: Section 5.1 of the specification is about class version compatibility, but not about Java version compatibility.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
bebe
  • 23
  • 4
  • 5
    Sure. That’s exactly what an explicit `serialVersionUID` is for. – Holger Sep 20 '17 at 13:42
  • @Holger Sure, but there is nothing about `serialVersionUID` in the question. – user207421 Sep 21 '17 at 09:18
  • @EJP: it was, before the question has been entirely rewritten. I thought, you should have enough experience with Stackoverflow to know that posts can be edited and how to compare the time of an edit with the time of a comment… – Holger Sep 21 '17 at 14:42

2 Answers2

2

Yes. The specification hasn't changed between Java 7 and 8 (or 9), and it guarantees compatibility except in the cases noted in the Object Versioning chapter. Note also that there are warnings in every javax.swing class about this.

user207421
  • 305,947
  • 44
  • 307
  • 483
2

Could somebody point me to the exact part of the specification which specifically adresses different major versions? If there is none, from what part can I deduce said compatibility?

http://docs.oracle.com/javase/8/docs/platform/serialization/spec/protocol.html#a5849 https://docs.oracle.com/javase/8/docs/platform/serialization/spec/protocol.html https://docs.oracle.com/javase/7/docs/platform/serialization/spec/protocol.html

You could see that protocol version is 6 in both cases:

Java Object Serialization Specification version 6.0

egorlitvinenko
  • 2,736
  • 2
  • 16
  • 36