I want to parse a string to a class which has a List as a field and also another object. Here's the class:
Result result;
List<Param> params;
and the string:
{
"result":{
"isOk":true,
"message":"OK"
},
"params":[
{
"id":123,
"name":"ASD"
},
{
"id":987,
"name":"QWE"
}
]
}
Based on the question I tried to use .use()
option but I only managed to get a HashMap. The documentation is not clear for me.
Edit: Now I've made some changes to figure this out and can't even get the hashmap...
Edit2: Okay, I got the hashmap but it's crazy.
I've managed to do:
HashMap<String, List<Params>> map =
new JSONDeserializer<HashMap<String, List<Params>>>()
.use("null", List.class)
.use("params", Params.class)
.deserialize(json);
then I do:
List<Params> params = mapa.get("params");
but Param param = params.get(0);
returns failed cast HashMap to Params...