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:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void getRelationships(Location location, JsonArray array) {
    for (int i = 0; i < array.size(); i++) {
        JsonObject ob = array.get(i).getAsJsonObject();

        Relationship r = new Relationship();
        r.setTerm(ob.get(TERM).getAsString());
        r.setBase(ob.get(BASE).getAsString());
        if (ob.has(TARGET_POI))
            r.setTargetPOI(ob.get(TARGET_POI).getAsString());

        if (ob.has(TARGET_EVENT))
            r.setTargetEvent(ob.get(TARGET_EVENT).getAsString());

        location.addRelationship(r);/*from w ww.  j ava2 s .c om*/
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void getTime(POI poi, JsonObject jObject) {
    JsonArray jArray = jObject.getAsJsonArray(TIME);
    for (int i = 0; i < jArray.size(); i++) {
        JsonObject ob = jArray.get(i).getAsJsonObject();
        POITermType term = getPOITermType(ob);

        if (ob.has(SCHEME))
            term.setScheme(ob.get(SCHEME).getAsString());

        poi.addTime(term);//from ww w  .  j  av  a  2  s  .c o m
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeListPois(ListPointOfInterest list, JsonObject jObject) {
    JsonElement jElement = jObject.get(POI);
    JsonArray jArray = jElement.getAsJsonArray();
    for (int i = 0; i < jArray.size(); i++) {
        PointOfInterest poi = new PointOfInterest();
        getSinglePOI(poi, jArray.get(i).getAsJsonObject());
        list.addPoi(poi);// w  w w.  j av  a 2s .c o  m
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeListEvents(ListEvent list, JsonObject jObject) {
    JsonElement jElement = jObject.get(EVENT);
    JsonArray jArray = jElement.getAsJsonArray();
    for (int i = 0; i < jArray.size(); i++) {
        Event event = new Event();
        getSinglePOI(event, jArray.get(i).getAsJsonObject());
        list.addEvent(event);/*from  ww w  .  j  a va2s .c o m*/
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeListRoutes(ListRoute list, JsonObject jObject) {
    JsonElement jElement = jObject.get(ROUTES);
    JsonArray jArray = jElement.getAsJsonArray();
    for (int i = 0; i < jArray.size(); i++) {
        Route route = new Route();
        getSinglePOI(route, jArray.get(i).getAsJsonObject());
        list.addRoute(route);//from   w  w w . ja va2  s.  c  o m
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializePoiBased(Deserializable poi, JsonObject json) {
    getSinglePOI((POI) poi, json);//w  ww  .  ja v a 2 s  .  c o  m

    // for routes
    if (json.has(POIS)) {
        JsonArray jArray = json.get(POIS).getAsJsonArray();
        ListPointOfInterest list = ((Route) poi).getListPoi();
        for (int i = 0; i < jArray.size(); i++) {
            PointOfInterest rPoi = new PointOfInterest();
            getSinglePOI(rPoi, jArray.get(i).getAsJsonObject());
            list.addPoi(rPoi);
        }
    }
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeResources(Resources resources, JsonObject jObject) {
    JsonElement jElement = jObject.get(TOURISM);
    JsonArray jArray = jElement.getAsJsonArray();
    for (int i = 0; i < jArray.size(); i++) {
        JsonObject ob = jArray.get(i).getAsJsonObject();
        HypermediaLink resource = getResource(ob);
        resources.addResource(resource);
    }/*from  w  w w.  ja v  a  2  s .  c o m*/
}

From source file:citysdk.tourism.client.parser.POIDeserializer.java

License:Open Source License

private void deserializeTags(ListTag list, JsonObject jObject) {
    JsonObject json = null;//from w ww. j  a  v a  2  s  .  c  om
    JsonArray array;
    POI tag;

    array = jObject.get(TAGS).getAsJsonArray();
    for (int i = 0; i < array.size(); i++) {
        tag = new Tag();
        json = array.get(i).getAsJsonObject();
        deserializeTag(tag, json.get(TAG).getAsJsonArray());
        list.add((Tag) tag);
    }
}

From source file:cl.emendare.cleancodegenerator.external.adapter.GsonJsonConverter.java

@Override
public Configuration toConfigurationObject() {

    JsonObject jsonObject = new JsonObject();

    try {//from   w  ww  .  j a v  a2  s . c om
        JsonElement jsonElement = parser.parse(new FileReader(filePath));
        jsonObject = jsonElement.getAsJsonObject();
    } catch (Exception e) {

    }

    Configuration config = factory.create(jsonObject.get("language").toString().replace("\"", ""),
            jsonObject.get("domain").toString().replace("\"", ""),
            jsonObject.get("persistence").toString().replace("\"", ""),
            jsonObject.get("usecase").toString().replace("\"", ""),
            jsonObject.get("module").toString().replace("\"", ""),
            jsonObject.get("package").toString().replace("\"", ""),
            jsonObject.get("author").toString().replace("\"", ""));

    return config;
}

From source file:cl.niclabs.cb.common.MethodParser.java

License:Open Source License

@Override
public Method deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    String method = jsonObject.get("method").getAsString();
    JsonElement argsJsonElement = jsonObject.get("args");
    switch (method) {
    case "OpenSession": {
        return methodFactory.makeOpenSessionMethod();
    }/*from   www.  java 2  s .  c o m*/
    case "CloseSession": {
        CloseSessionMethod.Args args = context.deserialize(argsJsonElement, CloseSessionMethod.Args.class);
        return methodFactory.makeCloseSessionMethod(args);
    }
    case "DeleteKeyPair": {
        DeleteKeyPairMethod.Args args = context.deserialize(argsJsonElement, DeleteKeyPairMethod.Args.class);
        return methodFactory.makeDeleteKeyMethod(args);
    }
    case "GenerateKeyPair": {
        GenerateKeyPairMethod.Args args = context.deserialize(argsJsonElement,
                GenerateKeyPairMethod.Args.class);
        return methodFactory.makeGenerateKeyPairMethod(args);
    }
    case "SignInit": {
        SignInitMethod.Args args = context.deserialize(argsJsonElement, SignInitMethod.Args.class);
        return methodFactory.makeSignInitMethod(args);
    }
    case "Sign": {
        SignMethod.Args args = context.deserialize(argsJsonElement, SignMethod.Args.class);
        return methodFactory.makeSignMethod(args);
    }
    case "FindKey": {
        FindKeyMethod.Args args = context.deserialize(argsJsonElement, FindKeyMethod.Args.class);
        return methodFactory.makeFindKeyMethod(args);
    }
    case "SeedRandom": {
        SeedRandomMethod.Args args = context.deserialize(argsJsonElement, SeedRandomMethod.Args.class);
        return methodFactory.makeSeedRandomMethod(args);
    }
    case "GenerateRandom": {
        GenerateRandomMethod.Args args = context.deserialize(argsJsonElement, GenerateRandomMethod.Args.class);
        return methodFactory.makeGenerateRandomMethod(args);
    }
    case "DigestInit": {
        DigestInitMethod.Args args = context.deserialize(argsJsonElement, DigestInitMethod.Args.class);
        return methodFactory.makeDigestInitMethod(args);
    }
    case "Digest": {
        DigestMethod.Args args = context.deserialize(argsJsonElement, DigestMethod.Args.class);
        return methodFactory.makeDigestMethod(args);
    }
    default: {
        throw new JsonParseException("Cannot parse method: " + method);
    }
    }

}