So I have this JSON structure I'm getting as a HTTP response. Structure looks like this:
{
"field1": "value1",
"field2": {
"field2-2": [
{
"field2-2-1": "some value",
"field2-2-2": {
"key" : "some value"
}
}
]
}
}
Of course I simplified it but you get the idea. Now I use Gson to convert it into a HashMap:
HashMap<String, Object> resultMap = new Gson().fromJson(httpResult, type);
Now, to get to the "field2-2-2" in Java I do this:
LinkedTreeMap someMap = (LinkedTreeMap) resultMap.get("field2");
ArrayList<LinkedTreeMap> someList = (ArrayList) someMap.get("field2-2");
LinkedTreeMap anotherMap = someList.get(0);
anotherMap.get("key");
Once again I simplified it, but is there any better way to access this "deep" field? Or for the sake of readability can I chain methods somehow? What I mean is if this all have been ArrayLists I could do something like:
ArrayList<Arraylist<String>> sampleList = new ArrayList<>();
sampleList.get(0).get(0);