Example usage for com.google.gson JsonObject entrySet

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

Introduction

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

Prototype

public Set<Map.Entry<String, JsonElement>> entrySet() 

Source Link

Document

Returns a set of members of this object.

Usage

From source file:ccm.pay2spawn.util.JsonNBTHelper.java

License:Open Source License

public static NBTTagCompound parseJSON(JsonObject data) {
    NBTTagCompound root = new NBTTagCompound();
    for (Map.Entry<String, JsonElement> entry : data.entrySet())
        root.setTag(entry.getKey(), parseJSON(entry.getValue()));
    return root;/*w w  w .  j a v  a  2s.c  o m*/
}

From source file:ccm.pay2spawn.util.JsonNBTHelper.java

License:Open Source License

public static JsonObject fixNulls(JsonObject object) {
    JsonObject newObject = new JsonObject();
    for (Map.Entry<String, JsonElement> entry : object.entrySet())
        newObject.add(entry.getKey(), fixNulls(entry.getValue()));
    return newObject;
}

From source file:cf.adriantodt.David.modules.db.I18nModule.java

License:LGPL

@PostReady
private static void load() {
    localizeLocal("botname", jda.getSelfUser().getName());
    localizeLocal("mention", jda.getSelfUser().getAsMention());

    JsonObject mainFile = new JsonParser().parse(i18nMain).getAsJsonObject();
    mainFile.entrySet().forEach(entry -> {
        //Before Load, Parse Contents
        JsonObject def = entry.getValue().getAsJsonObject();
        if (def.has("parent"))
            setParent(entry.getKey(), def.get("parent").getAsString());

        String resource = manager.get(entry.getKey() + ".json");
        if (resource == null)
            return;

        loadFile(entry.getKey(), new JsonParser().parse(resource));
    });//from www  .ja  v  a2 s . c  om
}

From source file:cf.adriantodt.David.modules.db.I18nModule.java

License:LGPL

private static void loadTranslation(String lang, String base, JsonElement src, List<Exception> post) {
    if (!src.isJsonObject())
        return;//from  w w  w.  j ava2 s.c o m
    JsonObject t = src.getAsJsonObject();

    t.entrySet().forEach(entry -> {
        if (ConfigUtils.isJsonString(entry.getValue())) {
            localize(lang, base + entry.getKey(), entry.getValue().getAsString());
        }
        if (entry.getValue().isJsonObject()) {
            loadTranslation(lang, base + entry.getKey() + ".", entry.getValue(), post);
        }
    });
}

From source file:ch.cern.db.flume.interceptor.JSONEventToCSVInterceptor.java

License:GNU General Public License

@Override
public Event intercept(Event event) {
    if (!(event instanceof JSONEvent))
        return event;

    StringBuilder csv = new StringBuilder();

    JsonObject json = ((JSONEvent) event).getJsonObject();
    boolean first = true;
    for (Entry<String, JsonElement> property : json.entrySet()) {
        if (first)
            first = false;/*from w w  w .  j av  a  2 s  .  c o m*/
        else
            csv.append(",");

        csv.append(property.getValue());
    }

    return EventBuilder.withBody(csv.toString().getBytes(), event.getHeaders());
}

From source file:ch.cern.db.flume.sink.elasticsearch.serializer.JSONtoElasticSearchEventSerializer.java

License:GNU General Public License

private void appendBody(XContentBuilder builder, Event event) throws IOException {
    JsonParser parser = new JsonParser();

    JsonObject json = parser.parse(new String(event.getBody())).getAsJsonObject();

    for (Entry<String, JsonElement> property : json.entrySet()) {

        if (property.getValue().isJsonNull()) {
            builder.nullField(property.getKey());

            continue;
        }/*from w  w w  .j  a  v a 2  s  .  c  o  m*/

        if (!property.getValue().isJsonPrimitive()) {
            builder.field(property.getKey(), property.getValue());

            continue;
        }

        JsonPrimitive primitiveValue = (JsonPrimitive) property.getValue();

        if (primitiveValue.isBoolean())
            builder.field(property.getKey(), primitiveValue.getAsBoolean());
        else if (primitiveValue.isNumber())
            if (primitiveValue.getAsString().indexOf('.') != -1)
                builder.field(property.getKey(), primitiveValue.getAsNumber().doubleValue());
            else
                builder.field(property.getKey(), primitiveValue.getAsNumber().longValue());
        else if (primitiveValue.isString())
            builder.field(property.getKey(), primitiveValue.getAsString());
    }
}

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

License:Open Source License

private HypermediaLink getResource(JsonObject ob) {
    HypermediaLink hypermediaLink = new HypermediaLink();
    hypermediaLink.setVersion(ob.get(VERSION).getAsString());

    if (ob.has(_LINK)) {
        JsonObject map = ob.getAsJsonObject(_LINK);
        Set<Entry<String, JsonElement>> keySet = map.entrySet();
        for (Entry<String, JsonElement> entry : keySet) {
            JsonElement element = entry.getValue();
            JsonObject value = element.getAsJsonObject();

            Hypermedia link = new Hypermedia();
            link.setHref(value.get(HREF).getAsString());
            link.setTemplated(value.get(TEMPLATED).getAsBoolean());

            hypermediaLink.addHypermedia(entry.getKey(), link);
        }//from w ww .ja v a 2s .  c  o m
    }

    return hypermediaLink;
}

From source file:classes.analysis.Analysis.java

License:Open Source License

private String getJsonElementAsString(JsonElement element) {
    String value = "";
    if (element == null) {
        return "-";
    } else if (element.isJsonArray()) {
        JsonArray array = element.getAsJsonArray();
        for (JsonElement subelement : array) {
            value = this.getJsonElementAsString(subelement);
        }//  w  w  w.ja v a2s  . c o m
    } else if (element.isJsonObject()) {
        JsonObject object = element.getAsJsonObject();

        for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
            value += entry.getKey() + ":" + this.getJsonElementAsString(entry.getValue());
        }
    } else if (element.isJsonPrimitive()) {
        value += element.toString().replaceAll("\"", "") + "\n";
    }
    return value;
}

From source file:client.utils.CommandsSettings.java

License:Apache License

private Map<String, String> makeMap(JsonObject arr) {
    Map<String, String> mp = new HashMap<>();
    Set<Map.Entry<String, JsonElement>> entries = arr.entrySet();
    for (Map.Entry<String, JsonElement> entry : entries) {
        mp.put(entry.getKey(),//from ww  w.  j  ava 2s .  co m
                entry.getValue().toString().substring(1, entry.getValue().toString().length() - 1));
    }
    return mp;
}

From source file:club.jmint.crossing.specs.ParamBuilder.java

License:Apache License

public static String checkSignAndRemove(String p, String signKey) throws CrossException {
    JsonParser jp = new JsonParser();
    JsonElement jop = null;/*from w w w .ja  v  a  2  s  .c om*/
    try {
        jop = jp.parse(p);
        if (!jop.isJsonObject()) {
            throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(),
                    ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo());
        }
    } catch (JsonSyntaxException jse) {
        //jse.printStackTrace();
        throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(),
                ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo());
    }

    JsonObject jo = (JsonObject) jop;
    String np = null;
    if (jo.has("sign") || jo.has("params")) {
        String sign = jo.getAsJsonPrimitive("sign").getAsString();
        np = jo.getAsJsonObject("params").toString();
        String signValue = Security.crossingSign(np, signKey, "");
        if (!sign.equals(signValue)) {
            throw new CrossException(ErrorCode.COMMON_ERR_SIGN_BAD.getCode(),
                    ErrorCode.COMMON_ERR_SIGN_BAD.getInfo());
        }

        //remove sign field only and return
        Iterator<Entry<String, JsonElement>> it = jo.entrySet().iterator();
        JsonObject rjo = new JsonObject();
        Entry<String, JsonElement> en;
        while (it.hasNext()) {
            en = it.next();
            if (!en.getKey().equals("sign")) {
                rjo.add(en.getKey(), en.getValue());
            }
        }
        return rjo.toString();
    }

    return p;
}