I have json response comming from service. For one element some time it is coming as json array and some time it is coming is json object.
Example:
Response 1:
{"_id":2,"value":{id: 12, name: John}}
Response 2:
{"_id":1,"value":[{id: 12, name: John}, {id: 22, name: OMG}]}
Here value is jsonObject in Response 1 and jsonArray in Response 2.
Problem is I am using Gson to parse the json. and kept the value as ArrayList in my POJO class.
public class ResponseDataset {
private int _id;
private ArrayList<Value> value;
// getter setter
}
public class Value {
private int id;
private String name;
// getter setter
}
Is there is any way I can handle this using Gson. My json response too large and complex so wanted to avoid line by line parsing.