CONTENTS | PREV | NEXT | Java Object Serialization Specification |
By default, the serializable fields of a class are defined to be the non-transient and non-static fields. These declarations can be overridden by declaring a special field in the class. For example, the declaration below duplicates the default behavior.class List implements Serializable { List next; public final static ObjectStreamField[] serialPersistentFields = {new ObjectStreamField("next", List.class)};}TheserialPersistentFields
field must be initialized with an array ofObjectStreamField
objects that list the names and types of the serializable fields. The field must be static and final so it does not change during operation.When an
ObjectStreamClass
is created for a class it examines the class to determine the serializable fields. It looks for the definition of theserialPersistentFields
and if it is not found then the list of serializable fields is created from the non-transient and non-static fields of the class.By using
serialPersistentFields
to define the Serializable fields for a class, there no longer is a limitation that a serialiable field must be a field within the current definition of the Serializable class. ThewriteObject
andreadObject
methods of theSerializable
class can map the current implementation of the class to the serializable fields of the class. Thus, the data representation for aSerializable
class can change in a later releases, as long as it maintains the mapping back to itsSerializable
fields that must remain compatibile across release boundaries.