Example usage for javax.json JsonObject containsKey

List of usage examples for javax.json JsonObject containsKey

Introduction

In this page you can find the example usage for javax.json JsonObject containsKey.

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:io.hakbot.util.JsonUtil.java

/**
 * Returns the value for the specified parameter name included in the specified json object. If json
 * object is null or specified name cannot be found, method returns null.
 *///w  w  w . j  av a  2s.  c o m
public static String getString(JsonObject json, String name) {
    return (json != null && json.containsKey(name)) ? json.getString(name) : null;
}

From source file:io.hakbot.util.JsonUtil.java

/**
 * Returns the value for the specified parameter name included in the specified json object. If json
 * object is null or specified name cannot be found, method returns null.
 *///from www . j av a2s. c o m
public static boolean getBoolean(JsonObject json, String name) {
    return (json != null && json.containsKey(name)) && json.getBoolean(name);
}

From source file:io.hakbot.util.JsonUtil.java

/**
 * Returns the value for the specified parameter name included in the specified json object. If json
 * object is null or specified name cannot be found, method returns -1.
 *///from w w w .  j  av  a 2  s.  c  o m
public static int getInt(JsonObject json, String name) {
    return (json != null && json.containsKey(name)) ? json.getInt(name) : -1;
}

From source file:io.hakbot.util.JsonUtil.java

/**
 * Returns a json object that is a child of the specified parent object with the specified name. If parent
 * is null or the specified name cannot be found, method will return null.
 *//* ww  w .j a  v  a2  s . c o m*/
public static JsonObject getJsonChildObject(JsonObject parent, String name) {
    return (parent != null && parent.containsKey(name)) ? parent.getJsonObject(name) : null;
}

From source file:io.hakbot.util.JsonUtil.java

/**
 * Returns the value for the specified parameter name included in the specified json object. If json
 * object is null or specified name cannot be found, method returns the specified default value.
 *//* w w w  .j a v  a2  s  . c om*/
public static int getInt(JsonObject json, String name, int defaultValue) {
    return (json != null && json.containsKey(name)) ? json.getInt(name, defaultValue) : defaultValue;
}

From source file:io.hakbot.util.JsonUtil.java

/**
 * Checks if the parameters specified (which are required) are used as
 * keys in the specified map//  www .j a va2  s  .c  om
 */
public static boolean requiredParams(JsonObject map, String... params) {
    for (String param : params) {
        if (!map.containsKey(param)) {
            return false;
        }
    }
    return true;
}

From source file:at.porscheinformatik.sonarqube.licensecheck.maven.MavenDependencyScanner.java

private static void parseDependencyJson(Set<Dependency> dependencies, JsonArray jsonDependencyArray) {
    for (int i = 0; i < jsonDependencyArray.size(); i++) {
        JsonObject jsonDependency = jsonDependencyArray.getJsonObject(i);
        String scope = jsonDependency.getString("s");
        if ("compile".equals(scope) || "runtime".equals(scope)) {
            if (jsonDependency.containsKey("d")) {
                parseDependencyJson(dependencies, jsonDependency.getJsonArray("d"));
            }//from w w w.  j  a va  2s .c  o m

            Dependency dependency = new Dependency(jsonDependency.getString("k"), jsonDependency.getString("v"),
                    null);
            dependencies.add(dependency);
        }
    }
}

From source file:com.buffalokiwi.aerodrome.jet.JetAPIResponse.java

/**
 * Check the response body for errors//from  w w w  .  j  ava 2 s. co  m
 * @param res JSON results
 * @throws JetException if there's an issue
 */
public static final void checkErrors(final JsonObject res, final IAPIResponse apiRes) throws JetException {
    if (res.containsKey("errors")) {
        final JsonArray errors = res.getJsonArray("errors");
        ArrayList<String> messages = new ArrayList<>();

        for (int i = 0; i < errors.size(); i++) {
            messages.add(errors.getString(i, ""));
        }

        throw new JetException(messages, null, apiRes);
    } else if (res.containsKey("error")) {
        throw new JetException(res.getString("error"), null, apiRes);
    }
}

From source file:org.kuali.rice.krad.uif.layout.collections.DataTablesPagingHelper.java

/**
 * Get the sort type string from the parsed column definitions object.
 *
 * @param jsonColumnDefs the JsonArray representation of the aoColumnDefs property from the RichTable template
 * options//from   w w  w  . ja v  a 2s .  com
 * @param sortCol the index of the column to get the sort type for
 * @return the name of the sort type specified in the template options, or the default of "string" if none is
 * found.
 */
private static String getSortType(JsonArray jsonColumnDefs, int sortCol) {
    String sortType = "string"; // default to string if nothing is spec'd

    if (jsonColumnDefs != null) {
        JsonObject column = jsonColumnDefs.getJsonObject(sortCol);

        if (column.containsKey("sType")) {
            sortType = column.getString("sType");
        }
    }
    return sortType;
}

From source file:org.apache.tamaya.etcd.EtcdAccessor.java

private static void parsePrevNode(String key, Map<String, String> result, JsonObject o) {
    if (o.containsKey("prevNode")) {
        final JsonObject prevNode = o.getJsonObject("prevNode");
        if (prevNode.containsKey("createdIndex")) {
            result.put("_" + key + ".prevNode.createdIndex", String.valueOf(prevNode.getInt("createdIndex")));
        }/*from w w w  . j av a2s  .  c om*/
        if (prevNode.containsKey("modifiedIndex")) {
            result.put("_" + key + ".prevNode.modifiedIndex", String.valueOf(prevNode.getInt("modifiedIndex")));
        }
        if (prevNode.containsKey("expiration")) {
            result.put("_" + key + ".prevNode.expiration", String.valueOf(prevNode.getString("expiration")));
        }
        if (prevNode.containsKey("ttl")) {
            result.put("_" + key + ".prevNode.ttl", String.valueOf(prevNode.getInt("ttl")));
        }
        result.put("_" + key + ".prevNode.value", prevNode.getString("value"));
    }
}