Spec-Zone .ru
спецификации, руководства, описания, API
blue bar

Using Serialization and the Serializable Fields API

blue bar

Abstract

This example shows how to use the Serializable Fields API with Serialization, demonstrating that the class can define fields other than those already in the class to be serializable. This differs from just rewriting the writeObject method to customize the data format (see the Custom Data Format example) because, in this example, versioning support still holds.

Using the Serializable Fields API, this example specifically changes the internal representation of a rectangle from x1,y1,x2,y2 implementation (see OriginalClass.java) to Point(x1,y1), Point(x2,y2) (see EvolvedClass.java) while the external representation still remains x1, y1, x2, y2. This ensures bidirectional compatibility between the original and evolved representations.

As with all examples dealing with evolution, here the evolved class (ARectangle) must define a serialVersionUID field that is obtained using the command serialver on the original class (ARectangle).

blue bar

Additional Information

Source Files
Running the Example
List of Examples
blue bar