32014Sep

Need Of serialVersionUID In Serialization

serialVersionUID In Serialization

If we do not explicitly declare serialVersionUID during serialization then JVM generates this ID based upon the structure of class.

And then if we implement another interface or any other class or change the structure of class then JVM will generate different serialVersionUID for the class. After that if we try to load old serialized object then there will be InvalidClassException.

Exception in thread “main” java.io.InvalidClassException:

So to avoid this exception best practice is always declare serialVersionUID while serialization.