Designing RMI Applications

Ensure Serialization of Instance-Level State

  1. Make the variable transient:
    private transient Object myobject[];
    so it will not get serialized (be careful!)
  2. Declare which variables should be stored by defining a special variable:
    private static final ObjectSreamField[] serialPersistentFields =
        { new ObjectStreamField("size", Integer.Type), ... };
  3. Do your own serialization by implementing
    private void writeObject(java.io.ObjectOutputStream out) throws IOException;
    private void readOject(java.io.ObjectInputStream in) 
           throws IOException, ClassNotFoundException;
    these methods can invoke defaultWriteObject() to invoke default serialization on the non-transient members.

José M. Vidal .

29 of 49