Search code examples
javaserializationprotostuff

Backward Compatibility when adding a field in response of an API


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


Solution

  • 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 .