|CONTENTS | PREV | NEXT||Java Object Serialization Specification|
Serialization provides two mechanisms for accessing the serializable fields in a stream:
The default mechanism is used automatically when reading or writing objects that implement the
Serializableinterface and do no further customization. The serializable fields are mapped to the corresponding fields of the class and values are either written to the stream from those fields or are read in and assigned respectively. If the class provides
readObjectmethods, the default mechanism can be invoked by calling
defaultReadObject. When the
readObjectmethods are implemented, the class has an opportunity to modify the serializable field values before they are written or after they are read.
When the default mechanism cannot be used, the serializable class can use the
ObjectOutputStreamto put the values for the serializable fields into the stream. The
ObjectOutputStreamputs the values in the correct order, then writes them to the stream using the existing protocol for serialization. Correspondingly, the
ObjectInputStreamreads the values from the stream and makes them available to the class by name in any order. See Section 2.2, "The ObjectOutputStream.PutField Class" and Section 3.2, "The ObjectInputStream.GetField Class." for a detailed description of the Serializable Fields API.