One of advantages of customized serialization is possibility to add transient fields (like inherited from other classes) into serialization process. You can do it like this
class NotMyClass implements Serializable {
String login;
transient String password;
//...
}
//I want to serialize also transient password field
class MyClass extends NotMyClass {
private void writeObject(ObjectOutputStream out) throws IOException {
System.out.println("defaul serialization");
out.defaultWriteObject();
System.out.println("my serialization >>>> adding inherited transient value");
out.writeObject(password);
}
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
System.out.println("defaul deserialization");
in.defaultReadObject();
System.out.println("my deserialization <<<< reading stored transient value");
password = (String) in.readObject();
}
}