In a previous article, Everything You Need to Know About Java Serialization Explained, I explained how we can serialize/deserialize one object using the Serializable
interface and explain how we can customize the serialization process using writeObject
and readObject
methods.
Disadvantages of Java Serialization Process
But these customizations are not sufficient because the JVM has full control of the serialization process and those customization logics are just additions to the default serialization process. We still have to use the default serialization logic by calling ObjectOutputStream.defaultWriteObject()
and ObjectInputStream.defaultReadObject()
from writeObject
and readObject
methods. And if we do not call these default methods, our object will not be serialized/deserialized.
Everything You Need to Know About Java Serialization Explained
In a previous article, we looked at five different ways to create objects in Java, I have explained how deserializing a serialized object creates a new object, and in this blog, I am going to discuss Serialization and Deserialization in details.
We will use below Employee
class object as an example for the explanation