Questions tagged [serialversionuid]

`serialVersionUID` is an optional attribute of Java classes to indicate the standard serialization/deserialization format version. Used to detect if a serialized object is incompatible with the deserialization process/class.

Documented in java.io.Serializable:

The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:

ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
122 questions
2
votes
1 answer

Java Serialized Class Saved To File - How can i ensure backwards compatibility?

I have written an Android App for producing and saving 'Photography Services' Contracts to the device as a file for later printing. The class is pretty much made up of integers, doubles and Strings (including base64_encoded signatures). The class…
wilson208
  • 346
  • 2
  • 7
2
votes
3 answers

How do I deserialize a Java object with various serialVersionUIDs?

Imagine I have a class Foo which has had the serialVersionUIDs 1, 3 and 17 in the past and I need to be able to read all three versions into Foo instances. How do I do that? I specifically need to know which version was saved in the byte stream, so…
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
2
votes
1 answer

Java Serialization: Any solution if serialVersionUID is updated wrong and already released.

We have a very old class which doesn't have serialVersionUID. 4 years back someone added serialVersionUID to this class with a random value. He should have used serialver tool to find the value and used it while adding serialVersionUID, but that was…
Varun
  • 1,014
  • 8
  • 23
2
votes
1 answer

Where do I change the setting in Eclipse so that it would generate serialVersionUID for Serializable classes?

I want Eclipse to generate a serialVersionUID for classes that implement Serializable. However, my Eclipse instance does not throw me a warning or an error when I create a class that implements Serializable. Also, it does not give an suggestion…
vk239
  • 1,014
  • 1
  • 12
  • 30
1
vote
2 answers

serialVersionUID no longer required from Java 5 onwards?

I recently read a comment saying that usage of serialVersionUID to make different versions of the same class compatible for serialization/deserialization is no longer needed from Java 5 onwards. Is this correct? Maybe it got mixed-up with covariant…
shrini1000
  • 7,038
  • 12
  • 59
  • 99
1
vote
1 answer

Why is Java Ignoring My serialVersionUID?

I've got a class which defines public static final Long serialVersionUID = 123L;. When I actually serialize it or even if I run it through Java's serialver.exe it comes back with an arbitrary auto-generated serialVersionUID dependent on the method…
Hammer Bro.
  • 965
  • 1
  • 10
  • 23
1
vote
1 answer

Cant understand my java.io.InvalidClassException: javax.swing.JComponent

I am using serialization to communicate with my server. This way My applet retrieves a JTree created in the server. In eclipse and appletViewer my applet works perfectly but when I try to launch my applet from my server I got this error on my…
lemoos
  • 167
  • 1
  • 4
  • 17
1
vote
1 answer

What is the purpose of using serialVersionUID here?

Possible Duplicate: Why should I bother about serialVersionUID? I was examining the Struts2 validation documentation. Even here it is defined: private static final long serialVersionUID = -7505437345373234225L; What is the purpose of using…
kamaci
  • 72,915
  • 69
  • 228
  • 366
1
vote
1 answer

Serializable class not found CLASSNAME error is thrown when moving class package(even thought serialVersionUID is stated in class)

I am working with Redis(via redisson) I have a DTO class that I am serializing an deserializing into Redis, the codec I am using is: org.redisson.codec.FstCodec when I move the class to a diffrent namespace despite setting the: serialVersionUID…
Roie Beck
  • 1,113
  • 3
  • 15
  • 30
1
vote
0 answers

What is causing serialVersionUID errors when integrating Weka, SPL, and Java?

I am trying to update a Weka classifier in SPL, changing the attributes used to classify each case. I updated all SPL files and type definitions, along with a Java file, to use the new set of attributes, and built a new .model file in Weka. However,…
M. Riebel
  • 93
  • 1
  • 1
  • 8
1
vote
1 answer

implicit SerialVersionID is used even after defining explicit ID, Why?

Here in my class I have provided the serialVersionUID explicitly, but while using 'serialver' command in command prompt for this same class the UID is generated by the system as well. Could anyone please throw some light over the understanding of…
Maha-Dev
  • 56
  • 6
1
vote
0 answers

Is it necessary to implements the serialisation, when DTO has json annotation (JsonIgnoreProperties etc)?

What is the role of providing manual serialVersionUID on performance tuning? We are using Object mapper to convert java to json and vice versa.
jaikee gupta
  • 29
  • 1
  • 5
1
vote
2 answers

serialVersionUID added to JSON

I am converting an object to JSON using com.google.code.gson:gson:2.2.4 library by using code: String json = new GsonBuilder().excludeFieldsWithModifiers(Modifier.PROTECTED).create().toJson(object); And in the JSON string "serialVersionUID" is…
Rajat Mehra
  • 1,462
  • 14
  • 19
1
vote
0 answers

Encounter "unexpected end of block data" when try to ignore the serialVersionUID of the serialized object(A List of Object)

We have serialized a list of object(Say ReportSetting) and persist as byte array field into database. But we haven't declared the serialVersionUID in the class before and after the class has been changed by adding some more fields, we got the below…
1
vote
0 answers

Should i serialize my exceptions if they will only be logged?

Am working on a small internal tool which for sure will not focus on scalability. I am 100% sure that there will not be any external dependencies to the code i am writing now or in the future - hence no worry on marshalling between different…
1 2 3
8 9