Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding serialVersionUID of serialized object

Tags:

Is there a way to determine the generated serialVersionUID of a serialized Java object?

The problem is that I serialized an object without explicitely specifying the serialVersionUID. Now the deserialization process complains about class incompatibilities. However I didn't change the class in a way which would make it incompatible. So I assume that it is enough to specify the serialVersionUID in the class as it is stored in the object data. In order to do this I need to read the serialVersionUID from the serialized data.

like image 440
paweloque Avatar asked Aug 24 '09 12:08

paweloque


1 Answers

This works for me:

long serialVersionUID = ObjectStreamClass.lookup(YourObject.getClass()).getSerialVersionUID();

Hope it helps you too.

like image 136
Martins Avatar answered Sep 18 '22 15:09

Martins