I am getting nested json object and json array as response while making ReST call. Nested json array and json object comes randomly. It may not be present as part of response everytime. I want to deserialize json in such a way that all the fields in json place at the root level of java object.
JSON Response
{
"data": {
"id":"42342sdz",
"details" : {
"username": "Username",
"location": "Location",
"history":[
{
"historyId":"34312cs", "historyDetail":"Some val", "datetime":"Some val",
"myObj":{
"myField" : "Some val"
}
},
{ "historyId":"34312cs", "historyDetail":"Some val", "datetime":"Some val"}
]
}
}
}
Java Object which I want to build by parsing above JSON response.
class ResponseObject {
String id;
String username;
String location;
List<History> historyList;
//Getters and Setters
}
class History {
String historyId;
String historyDetails
String datetime;
String myField;
//Getters and Setters
}