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.
Asked
Active
Viewed 26 times
1 Answers
0
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.

Steve Hu
- 358
- 2
- 10
-
I would prefer a map or a list myself but a lot of developers from Java EE would like to model the request/response with POJO. They just need to know that the decision tightly coupled provider and consumer. When light-codegen is used, it generates the model based on the specification from a central marketplace for each release. Things won't be too bad if it is managed carefully. – Steve Hu Oct 29 '19 at 19:08