How serialversionuid is calculated

Automatically generated serialVersionIds are a hash based on the method signatures, parameters and such like in the class. It's done this way so that the serialVersionId will change whenever you change your class, indicating to the serialization mechanism that there data/class are no longer compatible. That's the default.

When you define your own, just start with 1, and increment when the class is no longer compatible with previously serialized data.


It is calculated based on the structure of your class - fields, methods, etc. It is specified in the Object Serialization Specification - see this section for the exact format.

The spec describes what happens in no value is provided, but the autogeneration uses the same algorithm.

The sequence of items in the stream is as follows:

  • The class name.
  • The class modifiers written as a 32-bit integer.
  • The name of each interface sorted by name.
  • For each field of the class sorted by field name (except private static and private transient fields:
    • The name of the field.
    • The modifiers of the field written as a 32-bit integer.
    • The descriptor of the field.
  • If a class initializer exists, write out the following:
    • The name of the method, .
    • The modifier of the method, java.lang.reflect.Modifier.STATIC, written as a 32-bit integer.
    • The descriptor of the method, ()V.
  • For each non-private constructor sorted by method name and signature:
    • The name of the method, .
    • The modifiers of the method written as a 32-bit integer.
    • The descriptor of the method.
  • For each non-private method sorted by method name and signature:
    • The name of the method.
    • The modifiers of the method written as a 32-bit integer.
    • The descriptor of the method.