-
CSR
-
Resolution: Approved
-
P2
-
None
-
minimal
-
Addendum to the new-in-14 records preview-feature Serialization spec change document.
-
SE
Summary
Describe allowable types of evolution compatible changes to serializable record classes.
Problem
The record-specific Java Object Serialization specification is silent on the types of changes that can be made to record classes while maintaining compatibility with preview serial versions.
Solution
In subsection 5.6.2 - "Compatible Changes", add allowable types of evolution compatible changes that can be made to serializable record classes.
Specification
5.6.2 Compatible Changes
...
- Adding or removing a record component - When the record object being
reconstituted has a record component that does not occur in the stream, the
record class's canonical constructor will be passed the default value for
its type. If specific initialization is needed, the constructor can
initialize the component to a non-default value. Stream field values not
passed to the canonical constructor are effectively discarded.
- Changing a class from an ordinary class to a record class - A class that is
suitable to be converted from an ordinary class to a record class, and
relies on default serialization, may be changed to a record class. The
ordinary class should have `java.lang.Object` as its direct superclass, or
otherwise have no serializable state in its superclasses. The name and type
of the record class's components must match that of the name and type of the
ordinary class's serializable fields. Record objects are reconstructed
through the record class's canonical constructor. If the canonical
constructor throws an exception, say while checking invariants, then an
`InvalidObjectException` is thrown.
- Changing a class from a record class to an ordinary class - A record class
that relies on default serialization, may be changed to an ordinary class.
The ordinary class must declare an explicit `serialVersionUID`, whose value
is the same as that of the prior record class's `serialVersionUID`, or
`0L` if the prior record class does not have an explicit `serialVersionUID`
declaration. The name and type of the ordinary class's serializable fields
must match that of the name and type of the prior record class's components.
Viewable online at: https://cr.openjdk.java.net/~chegar/records/spec/records-serialization-addendum.html
- csr of
-
JDK-8234782 Discuss evolution of records in serialization spec
-
- Closed
-
- relates to
-
JDK-8237019 Serialization Specification changes for Records
-
- Resolved
-