CONTENTS | PREV | NEXT | Java Object Serialization Specification |
Object Serialization produces a stream with information about the Java(tm) classes for the objects that are being saved. For serializable objects, sufficient information is kept to restore those objects even if a different (but compatible) version of the implementation of the class is present. The interfaceSerializable
is defined to identify classes that implement the serializable protocol:package java.io; public interface Serializable {};The class of a serializable object must do the following:
- Implement the
java.io.Serializable
interface.- Identify the fields that should be serializable.Either explicitly declare them serializable using the
serialPersistentFields
member or use the transient keyword to denote nonserializable fields.- Have access to the no-arg constructor of its first nonserializable superclass.
The class of a serializable object can also implement the following:
ObjectOutputStream
andObjectInputStream
are designed and implemented to allow the serializable classes they operate on to evolve. Evolve in this context means to allow changes to the classes that are compatible with the earlier versions of the classes. Details of the mechanism to allow compatible changes can be found in Section 5.5, "Compatible Java(tm) Type Evolution."