W3docs

What is a serialVersionUID and why should I use it?

A serialVersionUID is a unique identifier for a serializable class. It is used to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization.

A serialVersionUID is a unique identifier for a serializable class. It is used during deserialization to verify that the sender and receiver have loaded classes that are compatible with respect to serialization. If the receiver's class has a different serialVersionUID than the one in the serialized data, deserialization will throw an InvalidClassException.

When implementing the Serializable interface, it is recommended to explicitly declare a serialVersionUID. This value should remain consistent across compatible versions of your class to prevent deserialization failures. If omitted, the Java runtime automatically calculates one based on the class name, superclass, implemented interfaces, and other structural details.

private static final long serialVersionUID = 1L;

By specifying a serialVersionUID, you maintain control over version compatibility and avoid unexpected InvalidClassException errors when class structures change.