0

I have a JSON payload coming from the server which is a list of Objects. I need a way to get the response and then check each object for a particular attribute and then decide which POJO object to decode each of those. I have checked StackOverflow and I have come across solutions like :

Gson gson = new Gson();
String json = response.getBody().toString();
if (checkResponseMessage(json)) {
    Pojo1 pojo1 = gson.fromJson(json, Pojo1.class);
} else {
   Pojo2 pojo2 = gson.fromJson(json, Pojo2.class);
}

here the json string is the entire string which is a list of objects, i need to drill down into the list, check an attribute in the object to determine which POJO to use. Any pointers or help appreciated! Thanks!

OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
user3570727
  • 10,053
  • 4
  • 17
  • 24

0 Answers0