I use Externalizable rather than Serializable. By using Externalizable it requires that your object has the following two methods:
public void readExternal(ObjectInput in)
throws IOException;
public void writeExternal(ObjectOutput out)
throws IOException;
In the readExternal you supply the mechanism for objects to be read such as:
//This assumes that x is of type myObject
x = (myObject)in.readObject();
In the writeExternal you supply the mechanism for objects to be written. I use this to write out an array, but I only write out the "used" elements, to save on traffic:
public Object[] pullPieces() {
Object[] result = new Object[pos];
System.arraycopy(all_obj,0,result,0,pos);
return result;
}
public void writeExternal(ObjectOut out)
throws IOException{
out.writeObject(pullPieces());
}
Hope this helps..