Serialization and De-Serialization in Java - DZone Java
What if We Are Trying to Serialize a Non-Serializable Object?
We will get a RuntimeException saying: Exception in thread "main" java.io.NotSerializableException: java.io.ObjectOutputStream.
What Is the serialVersionUID?
SerialVersionUID is an ID, which is stamped on an object when it gets serialized usually with the hashcode of the object. We can find serialVersionUID for the object by the serialver tool in Java.
Syntax: serialver classname
SerialVersionUID is used for version control of an object. The consequence of not specifying serialVersionUID is that when you add or modify any field in the class, then the already-serialized class will not be able to recover because the serialVersionUID was generated for the new class and the old serialized object will be different. The Java serialization process relies on correct serialVersionUID for recovering the state of the serialized object and throws java.io.InvalidClassException in case of serialVersionUID mismatch.
Read full article from Serialization and De-Serialization in Java - DZone Java
No comments:
Post a Comment