What's the difference between the SUID (Stream Unique IDentifier) and the private static member serialVersionUID?
Created Oct 25, 2000
Tim Rohaly
The SUID is one of a number of things that the serialization protocol writes to the stream in addition to the serialized object (other things include a magic number and the fully- qualified class name of the object). SUID is not the same as the static variable serialVersionUID, although SUID is computed using that field, if it exists. In psuedocode,
if (serialVersionUID is defined) then
SUID is set equal to serialVersionUID
else
SUID is computed algoritmically
Because serialVersionUID is a static member,
it is not written to the stream as part of the serialized object. Instead, serialization uses the serialVersionUID to compute the SUID. The SUID
is then sent to the stream as part of the stream protocol,
not as part of the object definition.
Deserializing requires two things:
- The serialized object. This does not include the static member serialVersionUID, but it does include the SUID, fully-qualified class name, etc.
- The .class file. This does include the static members.