|CONTENTS | PREV | NEXT||Java Object Serialization Specification|
For serializable objects, the
writeObjectmethod allows a class to control the serialization of its own fields. Here is its signature:
private void writeObject(ObjectOutputStream stream) throws IOException;Each subclass of a serializable object may define its own
writeObjectmethod. If a class does not implement the method, the default serialization provided by
defaultWriteObjectwill be used. When implemented, the class is only responsible for having its own fields, not those of its supertypes or subtypes.
writeObjectmethod, if implemented, is responsible for saving the state of the class. The
defaultWriteObjectmethod should be called before writing any optional data that will be needed by the corresponding
readObjectmethod to restore the state of the object. The responsibility for the format, structure, and versioning of the optional data lies completely with the class.