In Java it is strongly recommended that all serializable classes explicitly declare serialVersionUID since the default serialVersionUID computation is highly sensitive to class details and compiler implementation is unreliable.
What's so special about serialization in C#?
If we don't define a serialVersionUID state for a Serializable class, then Java will define one based on some properties of the class itself such as the class name, instance fields, and so on.
If a serializable class does not explicitly declare a serialVersionUID , then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification.
SerialVersionUID is a unique identifier for each class, JVM uses it to compare the versions of the class ensuring that the same class was used during Serialization is loaded during Deserialization. Specifying one gives more control, though JVM does generate one if you don't specify.
The serialVersionUID is specific to a class, not an object, since they are static. I don't think it matters if two different classes have the same serialVersionUID, since it is used in deserializing objects of the same class.
In .Net Serialization is less cranky than in Java.
By default it supports new fields just defaulting them, and it just ignore any data it doesn't expect.
You can still implement the same kind of version control by implementing the ISerializable interface in your class and adding your own custom VersionId to your class and check it there.
You can read more about this here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With