JavaAdvanced#serialization

How can you customize the serialization process?

Implement writeObject() and readObject() methods in the class to control exactly what gets written/read, useful for encrypting sensitive fields or handling versioning logic beyond default field-by-field serialization.

Example
private void writeObject(ObjectOutputStream out) throws IOException {
  out.defaultWriteObject();
  out.writeObject(encrypt(password));
}

Related Questions

1
JavaIntermediate#design-patterns

What is the Factory design pattern?

Open
2
JavaIntermediate#design-patterns

What is the Builder pattern and when should you use it?

Open
3
JavaIntermediate#design-patterns

What is the Observer pattern?

Open