Let\'s say we have 3 Classes:
class foo { // not a singleton
String s;
}
class bar {
foo f;
int i;
}
class baz {
foo sameF;
}
If you want more controll you could overwrite writeObject() and readObject()
and serialize yourself.
class bar {
...
private void writeObject(ObjectOutputStream stream) throws IOException {
// let version 1, later when you need to have versioning.
stream.writeInt(version);
stream.writeInt(i);
// leave out
// stream.writeObject(foo);
}
}
// read object the analog, see
http://docs.oracle.com/javase/6/docs/platform/serialization/spec/output.html#861