0

I have added a couple of new fields to a Json response of an object .It rus fine when we update the client to hit the API . But older versions of the API give a serialization error. I am using PROTOSTUFF to serialize and deserialize the object . How can I make the old version of client to ignore the new fields and continue to work properly . I have tried making the fields transient and @JsonIgnore Tag

Aman Kumar Sinha
  • 407
  • 6
  • 17
  • Possible duplicate of https://stackoverflow.com/questions/42847522/parse-json-with-optional-field – Scary Wombat May 31 '18 at 06:40
  • What about [useProtocolVersion](https://docs.oracle.com/javase/7/docs/api/java/io/ObjectOutputStream.html#useProtocolVersion(int)) – Rcordoval May 31 '18 at 06:41

2 Answers2

1

The solution was to add the extra fields at the end of all fields in the class instead of in the middle . PROTOSTUFF ignores the fields added at the end as unknown fields and doesn't throw an error .

Aman Kumar Sinha
  • 407
  • 6
  • 17
0

You need version control in your controller. You must implement a versioning mechanism to figure out which method should be called in witch version... it's near impossible to handle this issue with a single action in the controller.

See below link:

REST API Versioning

Introduction to API Versioning Best Practices

Hamed
  • 5,867
  • 4
  • 32
  • 56
  • The change is really small with addition of just two extra key-value pair . And Creating versioning for every is a big effort so i was looking for some hack – Aman Kumar Sinha May 31 '18 at 07:54