Is java object serialization compatible between 1.5 and 1.6

前端 未结 8 1891
灰色年华
灰色年华 2020-12-18 19:48

I am wondering whether it is safe to mix jdk 1.5 and 1.6 (Java 6) object serialization (biderctional communication). I searched for an explicit statement from sun concerning

8条回答
  •  失恋的感觉
    2020-12-18 20:13

    Have you read the Java Object Serialization Specification? There is a topic on versioning. There is also an article for class implementers: Discover the secrets of the Java Serialization API. Each release of Java is accompanied by compatibility notes.

    From the Java 6 spec on serialization:


    The goals are to:

    • Support bidirectional communication between different versions of a class operating in different virtual machines by:
      • Defining a mechanism that allows JavaTM classes to read streams written by older versions of the same class.
      • Defining a mechanism that allows JavaTM classes to write streams intended to be read by older versions of the same class.
    • Provide default serialization for persistence and for RMI.
    • Perform well and produce compact streams in simple cases, so that RMI can use serialization.
    • Be able to identify and load classes that match the exact class used to write the stream.
    • Keep the overhead low for nonversioned classes.
    • Use a stream format that allows the traversal of the stream without having to invoke methods specific to the objects saved in the stream.

提交回复
热议问题