1

Is there anyway to override java system classes' serialVersionUID?

Error example: java.io.InvalidClassException: java.util.Date; local class incompatible: stream classdesc serialVersionUID = 7523895402267505689, local class serialVersionUID = 7523967970034938905

Client and server have different versions of java. But since I know that classes are the same, I want to be able to use serialization.

alex347
  • 621
  • 7
  • 18

2 Answers2

0

You don't know that the classes are the same. They might be the same but if the version number has changed then anything internal could have changed.

You will need to serialize your data to something else(like a string) and deserialize it on the other end.

Mark Robinson
  • 3,135
  • 1
  • 22
  • 37
0

The first Answer of the Q&A found by Peter Newton has a promising approach. Basically, the sample code overloads the method that reads class descriptors from the stream and tweaks the serial version id. If you are doing this for multiple classes, you'd need to adjust the code accordingly.

But note that this is a rather dangerous thing to do. If the transmitted representation of the class is not compatible, you could end up with corrupted objects without any warning.

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216