Backward Compatibility when adding a field in response of an API

1.9k Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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 .

1
On

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