Example usage for javax.json JsonObject get

List of usage examples for javax.json JsonObject get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.jboss.as.test.integration.logging.formatters.JsonFormatterTestCase.java

private static void checkNonNull(final JsonObject json, final String key) {
    Assert.assertNotNull(String.format("Missing %s in %s", key, json), json.get(key));
}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

private static long getJsonLong(JsonObject obj, String prop) throws ChaincodeCollectionConfigurationException {
    JsonValue ret = obj.get(prop);
    if (ret == null) {
        throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop));
    }//  w w  w .j a v a2  s. com
    if (ret.getValueType() != JsonValue.ValueType.NUMBER) {
        throw new ChaincodeCollectionConfigurationException(
                format("property %s wrong type expected number got %s", prop, ret.getValueType().name()));
    }

    return Long.parseLong(ret.toString());

}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

private static int getJsonInt(JsonObject obj, String prop) throws ChaincodeCollectionConfigurationException {
    JsonValue ret = obj.get(prop);
    if (ret == null) {
        throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop));
    }//from  w w w .  jav  a  2s  . co  m
    if (ret.getValueType() != JsonValue.ValueType.NUMBER) {
        throw new ChaincodeCollectionConfigurationException(
                format("property %s wrong type expected number got %s", prop, ret.getValueType().name()));
    }

    return Integer.parseInt(ret.toString());

}

From source file:org.jboss.as.test.integration.logging.formatters.JsonFormatterTestCase.java

private static void validateStackTrace(final JsonObject json, final boolean validateFormatted,
        final boolean validateStructured) {
    if (validateFormatted) {
        Assert.assertNotNull(json.get("stackTrace"));
    } else {/*from  ww  w  .j a  v  a2  s.  c  o m*/
        Assert.assertNull(json.get("stackTrace"));
    }
    if (validateStructured) {
        validateStackTrace(json.getJsonObject("exception"));
    } else {
        Assert.assertNull(json.get("exception"));
    }
}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

private static JsonObject getJsonObject(JsonObject obj, String prop)
        throws ChaincodeCollectionConfigurationException {
    JsonValue ret = obj.get(prop);
    if (ret == null) {
        throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop));
    }/*from   w w  w .jav a2 s  .  c o m*/
    if (ret.getValueType() != JsonValue.ValueType.OBJECT) {
        throw new ChaincodeCollectionConfigurationException(
                format("property %s wrong type expected object got %s", prop, ret.getValueType().name()));
    }

    return ret.asJsonObject();

}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

private static JsonArray getJsonArray(JsonObject obj, String prop)
        throws ChaincodeCollectionConfigurationException {
    JsonValue ret = obj.get(prop);
    if (ret == null) {
        throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop));
    }/*from ww  w.  j  a v  a  2 s  .  c  o  m*/
    if (ret.getValueType() != JsonValue.ValueType.ARRAY) {
        throw new ChaincodeCollectionConfigurationException(
                format("property %s wrong type expected array got %s", prop, ret.getValueType().name()));
    }

    return ret.asJsonArray();

}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

private static String getJsonString(JsonObject obj, String prop)
        throws ChaincodeCollectionConfigurationException {
    JsonValue ret = obj.get(prop);
    if (ret == null) {
        throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop));
    }/*from www.j av a2  s.c o m*/
    if (ret.getValueType() != JsonValue.ValueType.STRING) {
        throw new ChaincodeCollectionConfigurationException(
                format("property %s wrong type expected string got %s", prop, ret.getValueType().name()));
    }

    return obj.getString(prop);

}

From source file:org.jboss.as.test.integration.logging.formatters.JsonFormatterTestCase.java

private static void validateStackTrace(final JsonObject json) {
    checkNonNull(json, "refId");
    checkNonNull(json, "exceptionType");
    checkNonNull(json, "message");
    checkNonNull(json, "frames");
    if (json.get("causedBy") != null) {
        validateStackTrace(json.getJsonObject("causedBy").getJsonObject("exception"));
    }//from ww  w . ja v a2  s .  c o m
}

From source file:org.apache.unomi.services.services.SegmentServiceImpl.java

public static void dumpJSON(JsonValue tree, String key, String depthPrefix) {
    if (key != null)
        logger.info(depthPrefix + "Key " + key + ": ");
    switch (tree.getValueType()) {
    case OBJECT:/*  w w  w  .  j av a2  s.c o m*/
        logger.info(depthPrefix + "OBJECT");
        JsonObject object = (JsonObject) tree;
        for (String name : object.keySet())
            dumpJSON(object.get(name), name, depthPrefix + "  ");
        break;
    case ARRAY:
        logger.info(depthPrefix + "ARRAY");
        JsonArray array = (JsonArray) tree;
        for (JsonValue val : array)
            dumpJSON(val, null, depthPrefix + "  ");
        break;
    case STRING:
        JsonString st = (JsonString) tree;
        logger.info(depthPrefix + "STRING " + st.getString());
        break;
    case NUMBER:
        JsonNumber num = (JsonNumber) tree;
        logger.info(depthPrefix + "NUMBER " + num.toString());
        break;
    case TRUE:
    case FALSE:
    case NULL:
        logger.info(depthPrefix + tree.getValueType().toString());
        break;
    }
}

From source file:com.Assignment4.Products.java

/**
 * converting integer into string and parsing it to jsonobject
 * @param s returns the query in the and executes the insert query
 * @throws ParseException/*from   w w  w  .  ja v a  2 s.  c  o m*/
 * @throws SQLException
 */
@POST
@Path("/product")
@Consumes(MediaType.APPLICATION_JSON)
public void createProducts(String str) throws ParseException, SQLException {

    JSONParser jparser = new JSONParser();
    JsonObject jobject = (JsonObject) jparser.parse(str);

    Object ID = jobject.get("id");
    String ProductID = ID.toString();
    int iD = Integer.parseInt(ProductID);

    Object Name = jobject.get("name");
    String name = Name.toString();

    Object Description = jobject.get("description");
    String description = Description.toString();

    Object Qty = jobject.get("quantity");
    String quantity = Qty.toString();
    int Quantity = Integer.parseInt(quantity);

    Connection conn = getConnection();
    Statement s = conn.createStatement();
    s.executeUpdate("INSERT INTO product VALUES ('" + iD + "','" + name + "','" + description + "','" + quantity
            + "' )");
}