CONTENTS | PREV | NEXT | Java Object Serialization Specification |
For Externalizable objects, only the identity of the class of the object is saved by the container; the class must save and restore the contents. TheExternalizable
interface is defined as follows:package java.io; public interface Externalizable extends Serializable { public void writeExternal(ObjectOutput out) throws IOException; public void readExternal(ObjectInput in) throws IOException, java.lang.ClassNotFoundException; }The class of an Externalizable object must do the following:
Note - ThewriteExternal
andreadExternal
methods are public and raise the risk that a client may be able to write or read information in the object other than by using its methods and fields. These methods must be used only when the information held by the object is not sensitive or when exposing it does not present a security risk.
Note - Inner classes associated with enclosing instances cannot have no-arg constructors, since constructors of such classes implicitly accept the enclosing instance as a prepended parameter. Consequently theExternalizable
interface mechanism cannot be used for inner classes and they should implement theSerializable
interface, if they must be serialized. Several limitations exist for serializable inner classes as well, however; see Section 1.10, "The Serializable Interface", for a full enumeration.
An Externalizable class can optionally define the following methods: