The Serialization Proxy Pattern, as defined in Joshua Bloch's Effective Java, is a robust approach to Java object serialization. Instead of serializing the original class directly, a static nested proxy class captures the logical state and is written to the byte stream. On deserialization, the proxy reconstructs the original instance via its public API. Implementation requires writeReplace() in the original class to substitute the proxy during serialization, readResolve() in the proxy to recreate the original, and readObject() throwing an exception to block artificial byte streams. Key advantages include reduced extralinguistic behavior, no restrictions on final fields, flexible instantiation (allowing subtype substitution), improved security, and better separation of concerns via SRP. Limitations include incompatibility with client-extendable classes, potential issues with circular object graphs, and a modest performance overhead (~14%).
Sort: