readResolve
readResolve is a special method in Java that allows a class to control its deserialization. When an object of a class that implements the readResolve method is deserialized, the Java deserialization mechanism will call this method. The method can then return a different object than the one that was originally created by the deserialization process. This is useful for several reasons, such as ensuring that only one instance of a singleton class is created, or returning a pre-existing object from a cache.
To implement readResolve, a class must define a method with the signature Object readResolve() throws ObjectStreamException.
A common use case for readResolve is to maintain singleton pattern during deserialization. If a class is
The readResolve method is part of Java's serialization API and is invoked after the default deserialization