Shall I use pojo vs JsonObject for rest calls

Recently I have stumbled upon a situation where my new team is heavily using JsonObject for doing rest data interchange. Their view is while using pojo we are binding tightly with the rest service, while jsonObject gives freedom. Also it saves from unnecessary data serialisation at the same time reducing number of classes heavily.

I have some points to encounter them as 1. Pojo gives more meaning to data and we are holding data with correct data type. 2. If we need only 2 fields of 10 fields of json, we can deserialize to 2 fields class with @jsonIgnore

I don't know exactly on the cost of deserialisation, but somehow I have a feeling it shouldn't be much difference.

Can someone help me understand which perspective is way to go. Some pros and cons etc.


1 answer

  • answered 2018-01-12 10:26 RishikeshDhokare

    It really depends on the situation and the nature of your application. If the data your are receiving has no fixed structure/field names/data types or it is ever changing then of course using JsonObject makes more sense.

    On the other hand, if it is of fixed structure and involves operations which access the fields, its better to go with pojo. It has better readability IMO.