I have a question about type casting. I have the following JSON String:
{"server":"clients","method":"whoIs","arguments":["hello"]}
I am parsing it to the following Map<String, Object>.
{arguments=[hello], method=whoIs, server=clients}
It is now possible to do the following:
request.get("arguments");
This works fine. But I need to get the array that is stored in the arguments. How can I accomplish this? I tried (for example) the following:
System.out.println(request.get("arguments")[0]);
But of course this didn’t work..
How would this be possible?
Most likely, value is a
java.util.List. So you would access it like:But for more convenient access, perhaps have a look at Jackson, and specifically its Tree Model:
Jackson can of course bind to a regular Map too, which would be done like:
But accessing Maps is a bit less convenient due to casts, and inability to gracefully handle nulls.