List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
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"); }/* ww w.j a v a 2s .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"); }/*w w w. j av a2 s . c o m*/ 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.LoginCredentials.java
@Override public void deserialize(String JSON) throws JSONException { JsonElement obj = new JsonParser().parse(JSON); this.username = obj.getAsJsonObject().get("username").getAsString(); this.password = obj.getAsJsonObject().get("password").getAsString(); }
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); }
From source file:clientcommunicator.operations.RoadBuildingCardRequest.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.spot1 = this.getLocation(obj.getAsJsonObject("spot1")); this.spot2 = this.getLocation(obj.getAsJsonObject("spot2")); }
From source file:clientcommunicator.operations.RobPlayerRequest.java
@Override public void deserialize(String JSON) throws JSONException { JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject(); this.playerThatsRobbingIndex = 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.location = new HexLocation(x, y); }
From source file:clientcommunicator.operations.RollNumberRequest.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.numberRolled = obj.get("number").getAsInt(); }