11

Based on a question on Java's serialVersionUID, is it necessary to define serialVersionUID when the serialization is JSON?

private static final long serialVersionUID = 234239427349L;

I understand that when a object is binary serialized (RPC, etc), the framework adds class metadata to know which version it got serialized to and reject if it mismathces. If the JSON does not have any serial version field (_v), then this appears useless. (although SONAR give warning!)

Community
  • 1
  • 1
ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75

1 Answers1

19

It is not necessary. It can be ignored. The serialVersionUID field is not relevant when serializing or deserializing JSON.

In fact, that field is only relevant if you are using the Java object serialization protocol; i.e. the standard ObjectInputStream and ObjectOutputStream classes.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I really needed to see this answer very much, in order to stop worrying about adding a generated UID on all my model classes. – asgs Jan 06 '19 at 20:38