I am looking for a better (better than what I am doing at the moment) way to extract some data out of a JSON file using Gson. Apparently, the desired data is partly but quite interleaved, something like this:
{
"media": {
"content": [
{
"node": { "text": "foo", "id": "123", "user": "somebody" }
}
]
},
"enabled": true,
"count": 0,
"token": "abc"
}
I know I could do something like this, but the approach is quite tedious:
GsonBuilder builder = new GsonBuilder();
jsonObject = builder.create().fromJson(jsonString, jsonObject.class);
class jsonObject {
Media media;
Boolean enabled;
Integer count;
String token;
class Media {
ArrayList<Node> content;
}
class Node {
HashMap<String,String> node;
}
}
So my question is if there exists a more elegant way to extract the fields? I would like to have a class like:
class jsonObject {
HashMap<String, String> node;
Boolean enabled;
Integer count;
String token;
}
Thank you very much. Any help and suggestions are appreciated.