0

A previous developer saved serialized objects to a number of different databases. Each time some development work was done before deploying to the new location. The serialVersionUID was left dynamic so each database has different object versions (Though similar enough that casting with a static serial id works).

I've been tasked with updating old sites with the new features. Reading and writing the serialized objects is quite a pain. I would really like to normalize them. These objects are deeply nested and polymorphic. Getting raw data and transcoding would be quite the task. Is there a fast way of normalizing the objects to a static serial id?

user207421
  • 305,947
  • 44
  • 307
  • 483
Lockless
  • 497
  • 1
  • 5
  • 12

2 Answers2

0

The serialVersionUID needs to be set explicitly to the value in the database. You will see the required value in the exception message when you deserialize an object and the local class has changed.

user207421
  • 305,947
  • 44
  • 307
  • 483
-1

I case anyone comes to my question first before finding an answer.

Make Java runtime ignore serialVersionUIDs?

Edit*

It was pointed out that I linked to the answer I did not specify the actual solution. The ObjectInputStream performs a UID check on objects being deseralized. By overriding the stream read mechanism and just not implementing the UID check the problem can be avoided.

But please don't store serialized data in a database. Persisting serialized data with classes that can change is just asking for trouble.

Community
  • 1
  • 1
Lockless
  • 497
  • 1
  • 5
  • 12