question related to REST call compatibility

36 Views Asked by At

I have a question related to REST call compatibility...say I have application-1 that understands some JSON that gets mapped to type-1 object, and it communicates with an upgraded application that sends JSON response of type-1 object but with added field, why do I get exception when I am converting JSON to object on application-1 sent by application-2? Are we not supposed to discard properties that we don't understand? I am using Config.getInstance().getMapper().convertValue(body, MyClass.class) to convert JSON to object.

1

There are 1 best solutions below

1
On

When you are using POJO to model the REST API provider and consumer, that means you have to upgrade both sides at the same time when structure of the data is changed.

However, if you are just using Map or List to model the interface, then you have much more flexibility in terms of service evolution.

I have written an article years ago about this topic and hope it helps. https://www.networknt.com/design/evolution/

When using Jackson ObjectMapper, there are options to ignore some fields in the payload. This can avoid some issues but not all. This is one of the REST issues compare with GraphQL, RPC, etc.