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
4
votes
3 answers

Will adding a method change the java-calculated serialVersionUid on my class?

If I have a class like this: public class Name implements Serializable { private final String firstName; private final String lastName; public Name(String firstName, String lastName) { this.firstName = firstName; …
Pete Doyle
  • 937
  • 7
  • 11
4
votes
1 answer

Java Externalizable serialVersionUID

If I implement Externalizable, will I need to specify serialVersionUID in that class for version compatibility? In other words, does Java check serialVersionUID while deserializing Externalizable objects?
shrini1000
  • 7,038
  • 12
  • 59
  • 99
4
votes
4 answers

Isn't suppressing warnings better option than adding serialVersionUID in this scenario?

A common scenario in web applications: application has lots of classes that need to be stored in Session and are Serializable developer gets a bunch of warnings about "Serializable class does not implement serialVersionUID" developer shrugs and…
user449236
  • 513
  • 1
  • 4
  • 6
4
votes
1 answer

Do i have to update the serialVersionUID for this change?

If i change this method: public void setCustom(Map custom) { this.custom = (LinkedHashMap)custom; } to: public void setCustom(LinkedHashMap custom) { this.custom = custom; } do i have to…
matteosilv
  • 585
  • 7
  • 13
4
votes
1 answer

Can HashMap serialized in 1.7, be used in 1.6?

I thought this would throw an error saying minor version number; But it didn't. And is working correctly. Can anyone point out, why does this work? I created a hashMap in application running on java 1.7, serialized it and sent it to an application…
4
votes
2 answers

how to load libsvm model in java after serialVersionUID has changed

I have trained libsvm model on weka and then I saved the model. Now I want to use this model in java. Classifier cls = (Classifier)weka.core.SerializationHelper.read(this.modelPath); I get this error "java.io.InvalidClassException:…
RockOnGom
  • 3,893
  • 6
  • 35
  • 53
4
votes
1 answer

how do I fix a bug in the scala-library.jar

I am building a Play! Framework application using Play! 2.2.1, sbt 0.13.0, and my local version of scala is 2.10.3. I have encountered a serialVersionUID problem when deserializing a particular file that I inherited from coworkers for working on…
Hal
  • 69
  • 7
4
votes
1 answer

The serializable class Employee does not declare a static final serialVersionUID field of type long

In my Eclipse I was trying example on serialization and I came across following warning I know what serialVersionUID is and what is it's significance in Serialization. I have following questions about this warning How does IDE assign default…
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
4
votes
1 answer

Java: Should serializable inner & anonymous classes have SerialVersionUID?

Although I'm not currently planning to serialize anything, I give all serializable outer classes, as well as static nested classes a SerialVersionUID, because that is the proper way to do it. However, I've read here that Serialization of inner…
4
votes
4 answers

How is serialVersionUID serialized in Java?

Class members (static) cannot be serialized. The reason is obvious - they are not held by the object(s) of the class. Since they are associated with the class (rather than the object of that class), they are stored separately from the…
Tiny
  • 27,221
  • 105
  • 339
  • 599
4
votes
4 answers

Why does the serialVersionUID field exist?

It has baffled me from the launch of the Serializable interface why I have to incorporate this field in all of my classes. I understand that this interface needs a unique identifier to mark the class but why cant they generate this at run-time. For…
nikdeapen
  • 1,581
  • 3
  • 15
  • 27
3
votes
2 answers

Special Identifiers: serialVersionUID and serialPersistentFields

I understand what these fields are and how to use them, but I'm wondering this: How does the Java compiler actually handle special fields like this in its compilation step? Does it really look for variables just based on their name? That seems very…
John Fisher
  • 305
  • 1
  • 13
3
votes
2 answers

How do I generate the serial version UID of a Java file from command line?

Background I am attempting to generate the serialVersionUID of my java files in eclipse but get the error described in Eclipse : Cannot generate a serial version ID. I have followed the directions in that question, but I have no missing path files…
isakbob
  • 1,439
  • 2
  • 17
  • 39
3
votes
2 answers

Hashcode as serialVersionUid

I read in an article that the default serialVersionUid provided by JVM is the hashcode of an object. If we don't override the hashcode method in a class, how will the hashcode be computed during deserializatio as normally hashcode is the memory…
Tck
  • 83
  • 6
3
votes
1 answer

serialversionUID does not match

I am fairly new to java and I have a class Products that is Serializable. I do not know what I did, but my programs stopped working and gave me this error : Exception in thread "main" java.io.InvalidClassException: cockeb.Product; local class…
Spectre6
  • 33
  • 1
  • 2
  • 6
1 2
3
8 9