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.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.RoadBuildingCardRequest.java

private EdgeLocation getLocation(JsonObject edgeObject) {
    int x = edgeObject.get("x").getAsInt();
    int y = edgeObject.get("y").getAsInt();
    EdgeDirection edgeDirection = Abbreviate.unAbbreviateEdge(edgeObject.get("direction").getAsString());
    return new EdgeLocation(new HexLocation(x, y), edgeDirection);
}

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();
}

From source file:clientcommunicator.operations.SendChatRequest.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.content = obj.get("content").getAsString();
}

From source file:clientcommunicator.operations.YearOfPlentyRequest.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.resource1 = ResourceType.valueOf(obj.get("resource1").getAsString().toUpperCase());
    this.resource2 = ResourceType.valueOf(obj.get("resource2").getAsString().toUpperCase());
}

From source file:clientcommunicator.Server.Cookie.java

/**
 * @throws MalformedCookieException The Cookie was not of the proper form
 * @pre The server has just successfully called login/register and this is the cookie response
 * @post getCompleteCookieString includes user information
 * @param userInformationCookieString The whole value of the "Set-cookie:" header.
 * Should be in the form of "catan.user=%7B%22name%22%3A%22Sam%22%2C%22password%22%3A%22sam%22%2C%
22playerID%22%3A0%7DPath=/"//from ww w  .j a  v  a  2s.co  m
 */
public int setUserCookieString(String userInformationCookieString) throws MalformedCookieException {
    userInformationCookieString = userInformationCookieString.trim();
    userInformationCookieString = userInformationCookieString.replaceFirst("catan.user=", "");
    userInformationCookieString = userInformationCookieString.substring(0,
            userInformationCookieString.length() - 7);
    String userPart = userInformationCookieString.substring(0, userInformationCookieString.length() - 1);
    //this.userInformationString = urlDecoded;
    JsonElement element = this.decodeJSON(userPart);
    if (element.isJsonObject()) {
        JsonObject jobject = this.getUserJsonObject(element, true);
        return jobject.get("playerID").getAsInt();
    } else {
        throw new MalformedCookieException();
    }
}

From source file:clientcommunicator.Server.Cookie.java

private JsonObject getUserJsonObject(JsonElement element, boolean setNew) throws MalformedCookieException {
    JsonObject jobject = element.getAsJsonObject();
    if (!jobject.has("playerID")) {
        throw new MalformedCookieException();
    }//  w  ww  .j  av  a 2s .  co m
    JsonObject resultingCookie = new JsonObject();
    resultingCookie.add("name", jobject.get("name"));
    resultingCookie.add("password", jobject.get("password"));
    resultingCookie.add("playerID", jobject.get("playerID"));
    if (setNew) {
        try {
            String realCookie = resultingCookie.toString();
            realCookie = java.net.URLEncoder.encode(realCookie, "UTF-8");
            this.userInformationString = realCookie;
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Cookie.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return jobject;
}

From source file:clientcommunicator.Server.Cookie.java

/**
 *
 * @param incomingCookie The cookie value that is coming into the server
 * @return The user information contained within the cookie, null otherwise
 *///from   w  w  w  .  j a  v  a2  s.c  o m
public User getUser() {
    if (this.userInformationString == null)
        return null;
    try {
        JsonObject userJSONObject = this.getUserJsonObject(this.decodeJSON(this.userInformationString), false);
        User myUser = new User(userJSONObject.get("name").getAsString(),
                userJSONObject.get("password").getAsString());
        myUser.setPlayerId(userJSONObject.get("playerID").getAsInt());
        return myUser;
    } catch (MalformedCookieException e) {
        return null;
    }
}

From source file:cloud.google.datastore.entity.commit.Commit.java

License:Apache License

private String getTransaction() {
    String result = ConnectionService
            .connect(GCDStatic.getDatastoreApiUrl() + config.getProjectName() + "/beginTransaction").body("")
            .accessToken(AuthenticationFactory.getInstance(config).getAccessToken()).post();
    JsonElement jelement = new JsonParser().parse(result);
    JsonObject jobject = jelement.getAsJsonObject();
    jelement = jobject.get("transaction");
    return jelement != null ? jelement.getAsString() : "";
}