Versioning raises some fundamental questions about identity of a class, including what constitutes a compatible change, that is a change that does not affect the contract between the class and its callers.
This note describes the goals, assumptions, and a solution that attempts to address this problem by restricting the kinds of changes allowed and by carefully choosing the mechanisms.
The proposed solution provides a mechanism for "automatic" handling of classes that evolve by adding fields and adding classes. Serialization will handle versioning without class specific methods to be implemented for each version. The stream format can be traversed without invoking class specific methods.
For the purposes of the discussion here, each class implements and extends the interface or contract defined by its supertype. New versions of a class, for example foo', must continue to satisfy the contract for foo and may extend the interface or modify its implementation.
Communication between objects via Serialization is not part of the contract defined by these interfaces. Serialization is a private protocol between the implementations. It is the responsibility of the implementations to communicate sufficiently to allow each implementation to continue to satisfy the contract expected by its clients.
The following are the principle aspects of the design for versioning of serialized object streams.
defaultWriteObject
and read by calling defaultReadObject
.
The descriptions are from the perspective of the stream being read in order to reconstitute either an earlier or later version of the class. In the parlance of RPC systems, this is a "receiver makes right" system. The writer writes its data in the most suitable form and the receiver must interpret that information to extract the parts it needs and to fill in the parts that are not available.
defaultReadObject
first before reading any optional data. The writeObject
method is expected as usual to call defaultWriteObject
to write the required data and then may write optional data.
Copyright © 1996 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043-1100 USA. All rights reserved.