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
3
votes
1 answer

How to send Kryo serialized objects over JMS?

I would like to use Kryo to (de-)serialize objects and send/receive them via JMS. The problem I'm having is that both sides, sender and receiver, must register the classes with the same ID. Kryo has a method register (Class type, int id) that I use.…
Frizz
  • 2,524
  • 6
  • 31
  • 45
3
votes
1 answer

why Java declared serialVersionUID in Exception and Throwable class?

when I created one custom exception class just like below public class MyApppException extends Exception { private String message = null; public MyApppException() { super(); } public MyApppException(String message) { …
Rajorshi Roy
  • 632
  • 1
  • 7
  • 15
3
votes
2 answers

Why is method name considered or generating the hash for serialversionuid

I have a class while serialization public class Name implements Serializable { private final String firstName; private final String lastName; public Name(String firstName, String lastName) { this.firstName = firstName; …
3
votes
3 answers

negative serialVersionUID?

I came across a exception handler class that extends exception as follows: public class AppFileReaderException extends Exception { //Explicit serialization UID added private static final long serialVersionUID = -2458461415998318236L; …
Shan
  • 5,054
  • 12
  • 44
  • 58
3
votes
2 answers

Recommend declaration of a constant through an interface

I've been playing with the serializable interface for a little pet project of mine for a while, and I often notice a warning about how I should define static final long serialVersionID. I've been searching for a way to make my own interfaces produce…
Santo Guevarra
  • 385
  • 4
  • 8
3
votes
4 answers

If I change the base class that a Java Exception class extends, do I need to update the serialVersionUID value?

Consider the following Java exception classes: public class BarException extends RuntimeException { // [...] } public class FooException extends BarException { private static final long serialVersionUID = -5322002268075295537L; //…
Daniel Fortunov
  • 43,309
  • 26
  • 81
  • 106
2
votes
1 answer

how do I randomly generate a serialVersionUID in java?

whenever I see this line of code private static final long serialVersionUID = it's always followed by some long serial number.. how is this number generated? If I wanted to randomly generate this value, how would I go about that? thanks for any…
Elaina Heraty
  • 51
  • 1
  • 3
2
votes
1 answer

Sonarqube error: Class defines a computed serialVersionUID that doesn't equate to the calculated value

Correctness - Class defines a computed serialVersionUID that doesn't equate to the calculated value This serializable class defines a serialVersionUID that appears to be a computed value, however the value does not match the computed value, and thus…
2
votes
1 answer

Deserialization raises InvalidClassException even when serialVersionUID is set

Some time ago I published an app that serialized/deserialized an user object. public String serializeUser(final User user) { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { final…
cavpollo
  • 4,071
  • 2
  • 40
  • 64
2
votes
4 answers

Java - Modifying serialVersionUID of binary serialized object

A few months back I serialized a java.io.Serializable object into a file. Now I need to read the contents, but since then the serialVersionUID has changed, and now I'm getting a "class incompatible" error. I know for a fact that none of the data…
bajafresh4life
  • 12,491
  • 5
  • 37
  • 46
2
votes
1 answer

why is not safe to rely on ObjectStreamClass.getSerialVersionUID?

The java spec says: "it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler…
ejaenv
  • 2,117
  • 1
  • 23
  • 28
2
votes
1 answer

SerialVersionUID JavaDoc?

When adding documentation to my Java program, I realize that most classes require a serialVersionUID constant property to be declared. How exactly should I document this property? And do I document it differently if I used a default vs. generated…
rolling_codes
  • 15,174
  • 22
  • 76
  • 112
2
votes
1 answer

Is serialVersioUID require in Interfaces(I hope not)?

My understanding is serialVersionUID is applicable only to classes, because we can create an object only to classes and the concept of serialVersionUID is for object serialization and deserialization.
learner
  • 625
  • 2
  • 11
  • 25
2
votes
1 answer

How to generate serialVersionUID for anonymous class?

This is what I tried: I built the project with the -Xlint:serial option, and I got this warning: MyClass.java:42: warning: [serial] serializable class has no definition of serialVersionUID SerializableClass…
user
  • 6,567
  • 18
  • 58
  • 85
2
votes
1 answer

Why is SAXException serializable?

I have the following situation: public class MyHandler extends DefaultHandler { public class CustomException extends SAXException { } } Eclipse is telling me that SAXException is serializable, and that I should either add a…
0x5C91
  • 3,360
  • 3
  • 31
  • 46
1 2 3
8 9