This shouldn't be parsed as a List<Map<String, String>>, because what
you have is a JsonObject with a nested JsonArray inside that object.
One approach would be:
Message.java
===========
import com.google.gson.Gson;
import java.util.List;
import java.util.Map;
class Message {
String ip;
String game;
String zone;
List<Map<String, String>> rooms;
@Override
public String toString() {
StringBuilder roomsBuilder = new StringBuilder();
for (Map<String, String> room: rooms) {
roomsBuilder.append("\n");
for (Map.Entry<String, String> prop: room.entrySet()) {
roomsBuilder.append(" ")
.append(prop.getKey()).append(": ")
.append(prop.getValue()).append("\n");
}
}
return String.format("ip: %s\ngame: %s\nzone: %s\nrooms:\n%s",
ip, game, zone, roomsBuilder.toString());
}
public static void main(String[] args) {
Message msg = new
Gson().fromJson("{\"ip\":\"184.72.42.15\",\"game\":\"Game\",\"zone\":\"Blitz\",\"rooms\":[{\"id\":\"901\",\"left\":\"1\",\"maxplayers\":\"300\",\"players\":\"0\",\"cards_to_winners\":\"0.12\",\"cards\":\"0\",\"threshold\":\"1\",\"city\":\"New
York-744662523\"}]}", Message.class);
System.out.println(msg);
}
}
===========
$ java -cp gson-2.2.1.jar:. Message
ip: 184.72.42.15
game: Game
zone: Blitz
rooms:
id: 901
left: 1
maxplayers: 300
players: 0
cards_to_winners: 0.12
cards: 0
threshold: 1
city: New York-744662523
Another approach to building your own class is to use JsonParser to
fetch a JsonElement from the JSON. Then, you can use the
JsonObject/JsonArray API to pull the information out of the structure.