Friday, 30 August 2013

What is the easiest way to get a java.util.List from a com.google.gson.JsonArray?

What is the easiest way to get a java.util.List from a
com.google.gson.JsonArray?

The JsonObject named mapping has the following content:
{
"client":"127.0.0.1",
"servers":[
"8.8.8.8",
"8.8.4.4",
"156.154.70.1",
"156.154.71.1"
]
}
Thus, the Java statement
System.out.println(mapping.get("servers").getAsJsonArray().toString());
will have an output of
["8.8.8.8","8.8.4.4","156.154.70.1","156.154.71.1"]What could be the
easiest way to get those IP Addresses and put them into a java.util.List
other than looping-it-and-use-java.util.List.add() ?

No comments:

Post a Comment