Example usage for com.google.gson JsonObject get

List of usage examples for com.google.gson JsonObject get

Introduction

In this page you can find the example usage for com.google.gson JsonObject get.

Prototype

public JsonElement get(String memberName) 

Source Link

Document

Returns the member with the specified name.

Usage

From source file:clientcommunicator.operations.BuildCityRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
    JsonObject vertLocation = obj.get("vertexLocation").getAsJsonObject();
    int x = vertLocation.get("x").getAsInt();
    int y = vertLocation.get("y").getAsInt();
    String direction = vertLocation.get("direction").getAsString();
    this.location = new VertexLocation(new HexLocation(x, y), Abbreviate.unAbbreviateVertex(direction));
}

From source file:clientcommunicator.operations.BuildRoadRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
    JsonObject roadLocation = obj.getAsJsonObject("roadLocation");
    this.free = obj.get("free").getAsBoolean();
    int x = roadLocation.get("x").getAsInt();
    int y = roadLocation.get("y").getAsInt();
    String direction = roadLocation.get("direction").getAsString();
    this.location = new EdgeLocation(new HexLocation(x, y), Abbreviate.unAbbreviateEdge(direction));
}

From source file:clientcommunicator.operations.BuildSettlementRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.free = obj.get("free").getAsBoolean();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
    JsonObject vertLocation = obj.get("vertexLocation").getAsJsonObject();
    int x = vertLocation.get("x").getAsInt();
    int y = vertLocation.get("y").getAsInt();
    String direction = vertLocation.get("direction").getAsString();
    this.location = new VertexLocation(new HexLocation(x, y), Abbreviate.unAbbreviateVertex(direction));
}

From source file:clientcommunicator.operations.BuyDevCardRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
}

From source file:clientcommunicator.operations.CreateGameRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    if (!obj.has("randomTiles") || !obj.has("randomNumbers") || !obj.has("randomPorts") || !obj.has("name")) {
        throw new JSONException("Malformed CreateGameRequest: missing field");
    }/*from ww w. j  av  a2  s .c o m*/
    String randomTilesJSON = obj.get("randomTiles").getAsString();
    randomTilesJSON = randomTilesJSON.toLowerCase();
    if (randomTilesJSON.equals("true") && randomTilesJSON.equals("false") && randomTilesJSON.equals("1")
            && randomTilesJSON.equals("0")) {
        throw new JSONException("Malformed CreateGameRequest: invalid randomTiles");
    }
    String randomNumbersJSON = obj.get("randomNumbers").getAsString();
    randomNumbersJSON = randomNumbersJSON.toLowerCase();
    if (randomNumbersJSON.equals("true") && randomNumbersJSON.equals("false") && randomNumbersJSON.equals("1")
            && randomNumbersJSON.equals("0")) {
        throw new JSONException("Malformed CreateGameRequest: invalid randomNumbers");
    }
    String randomPortsJSON = obj.get("randomPorts").getAsString();
    randomPortsJSON = randomPortsJSON.toLowerCase();
    if (randomPortsJSON.equals("true") && randomPortsJSON.equals("false") && randomPortsJSON.equals("1")
            && randomPortsJSON.equals("0")) {
        throw new JSONException("Malformed CreateGameRequest: invalid randomPorts");
    }
    this.randomTiles = obj.get("randomTiles").getAsBoolean();
    this.randomNumbers = obj.get("randomNumbers").getAsBoolean();
    this.randomPorts = obj.get("randomPorts").getAsBoolean();
    this.name = obj.get("name").getAsString();
}

From source file:clientcommunicator.operations.DiscardCardsRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
    JsonObject resourceCards = obj.getAsJsonObject("discardedCards");
    int brick = resourceCards.get("brick").getAsInt();
    int ore = resourceCards.get("ore").getAsInt();
    int sheep = resourceCards.get("sheep").getAsInt();
    int wheat = resourceCards.get("wheat").getAsInt();
    int wood = resourceCards.get("wood").getAsInt();
    this.discardedCards = new ResourceCards(brick, wheat, wood, ore, sheep);
}

From source file:clientcommunicator.operations.JoinGameRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    if (!obj.has("id") || !obj.has("color")) {
        throw new JSONException("Malformed JoinGameRequest: missing field");
    }//from w  ww .j a  va  2s.  c  om
    String color = obj.get("color").getAsString().toUpperCase();
    if (!"RED".equals(color) && !"ORANGE".equals(color) && !"YELLOW".equals(color) && !"BLUE".equals(color)
            && !"GREEN".equals(color) && !"PURPLE".equals(color) && !"PUCE".equals(color)
            && !"WHITE".equals(color) && !"BROWN".equals(color)) {
        throw new JSONException("Malformed JoinGameRequest");
    }
    this.playerColor = CatanColor.valueOf(color);
    this.gameId = obj.get("id").getAsInt();
}

From source file:clientcommunicator.operations.MaritimeTradeRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
    this.ratio = obj.get("ratio").getAsInt();
    this.inputResource = ResourceType.valueOf(obj.get("inputResource").getAsString().toUpperCase());
    this.outputResource = ResourceType.valueOf(obj.get("outputResource").getAsString().toUpperCase());
}

From source file:clientcommunicator.operations.MonopolyRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
    this.resource = ResourceType.valueOf(obj.get("resource").getAsString().toUpperCase());
}

From source file:clientcommunicator.operations.PlaySoldierRequest.java

@Override
public void deserialize(String JSON) throws JSONException {
    JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject();
    this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt());
    this.victimIndex = new NullablePlayerIdx(obj.get("victimIndex").getAsInt());
    JsonObject locationObj = obj.getAsJsonObject("location");
    int x = locationObj.get("x").getAsInt();
    int y = locationObj.get("y").getAsInt();
    this.newLocation = new HexLocation(x, y);
}