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
11
votes
5 answers

How to generate serialVersionUID programmatically in Java?

I am working on a project that generates Java files. I'd like to be able to optionally add the serialVersionUID as you would with the serialver tool. Is there a way to do this when I generate the Java code, or will I need to ask the user of the…
bn.
  • 7,739
  • 7
  • 39
  • 54
11
votes
4 answers

About generated serialVersionUID in Eclipse

Is there any way to generate serialVersionUID in Eclipse serially? By serially I want to mean that if one serializable class has serialVersionUID = 1L, then when I generate serialVersionUID of another class this will be serialVersionUID = 2L. If I…
Tapas Bose
  • 28,796
  • 74
  • 215
  • 331
10
votes
2 answers

Why would the Java compiler create a serialVersionUID synthetic field?

As part of debugging an application, I noticed that Field.getDeclaredFields() returns some synthetic fields, including a serialVersionUID field in a class extending an interface, although none extend Serializable. Why does the compiler add such…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
10
votes
3 answers

Why isn't the serialVersionUID automatically generated?

Why isn't the serialVersionUID automatically generated? I was running into an issue on an application server where apparently an old class was being cached.
Walter White
10
votes
2 answers

Pickled Object Versioning

I am working on a project where we have a large number of objects being serialized and stored to disk using pickle/cPickle. As the life of the project progresses (after release to customers in the field) it is likely that future features/fixes will…
Paul Osborne
  • 5,024
  • 6
  • 24
  • 20
8
votes
1 answer

scala class serialization, impossible to fix SerialVersionUID

I'm currently testing remote actors to communicate between Android and Windows. Actors remote sends differents classes where I set the serialVersionUID. This is the code of my serialized class: @SerialVersionUID(13.asInstanceOf[Long]) case class…
reevolt
  • 797
  • 1
  • 9
  • 24
8
votes
1 answer

SerialVersionUID in the Java standard library across different JVMs

Based on the description of SerialVersionUID here: https://docs.oracle.com/javase/8/docs/platform/serialization/spec/class.html#a4100, it seems necessary to always include SerialVersionUID in any classes you create so that a JVM used for…
Nile
  • 1,586
  • 1
  • 14
  • 25
8
votes
3 answers

Why do we need serialVersionUID when extending RuntimeException?

Why do we need serialVersionUID when extending RuntimeException? Is RuntimeException a serializable class? public class DataNotFoundException extends RuntimeException { /** * */ private static final long serialVersionUID =…
8
votes
1 answer

serialized lambda and no serialVersionUID?

I'm trying to learn how the serialization works with Java and its lastest version. I'm trying to serialize a lambda like this : Runnable r = (Runnable & Serializable)() -> {System.out.println("This is a test");}; But I notice that I have no warning…
Thomas Betous
  • 4,633
  • 2
  • 24
  • 45
8
votes
1 answer

How to get rid of InvalidClassException SerialVersionUID?

I had saved one java object in the Database and then after few days I changed my jre version. Now when i tried to read that same object I am getting following exception: Exception in thread "main" java.io.InvalidClassException: SerializeMe; local…
milind_db
  • 1,274
  • 5
  • 34
  • 56
7
votes
3 answers

what is the different between default and generated serial version uid in java?

I don't know exactly where to use default serialVersionUID or generated serialVersionUID in java ? private static final long serialVersionUID = 4125965356358329466L; // generated private static final long serialVersionUID = 1L; // default
Savan Javia
  • 309
  • 4
  • 14
7
votes
5 answers

Can NetBeans generate an automatic serial version ID for a Java class?

I would like to remove some warnings for some classes by generating an automatic serial version ID. In Eclipse, this is trivial to do - the IDE can generate one automatically and add it to the class. However, I don't see this functionality in…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
6
votes
2 answers

Benefit of generated serialVersionID instead of 1L, 2L,

I have a discussion with a colleague about the serialVersionUID of serializable classes: He always start with a serialVersionUID = 1L and then increments it by one when there are some significant changes to the class. The JDK classes always seem to…
Sebastian S.
  • 1,545
  • 6
  • 24
  • 41
5
votes
2 answers

What algorithm is used by eclipse to generate verison id in Serializable class?

Suppose here is my class : class B implements Serializable { private static final long serialVersionUID = -5186261241138469827L; // what algo is used to generate this .......... } What algorithm eclipse uses to generate serialVersionUID…
Prateek
  • 12,014
  • 12
  • 60
  • 81
5
votes
3 answers

auto generation of serial version uid using maven2 plugin

Is there a maven plugin which automatically calculates and updates serial version uid for all java class files implementing the Serializable interface?
Joe
  • 14,513
  • 28
  • 82
  • 144
1
2
3
8 9