Example usage for com.fasterxml.jackson.databind JsonNode get

List of usage examples for com.fasterxml.jackson.databind JsonNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static int intFromJsonNode(JsonNode node, String key, int defaultValue) {
    if (node == null)
        return defaultValue;
    JsonNode value = node.get(key);
    if (value == null)
        return defaultValue;
    return value.asInt();
}

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static List<String> stringListFromJsonNode(JsonNode node, String key) {
    if (node == null)
        return new ArrayList<String>(0);
    JsonNode value = node.get(key);
    if (value == null)
        return new ArrayList<String>(0);

    ArrayNode arrayNode = (ArrayNode) value;
    ArrayList<String> result = new ArrayList<String>(arrayNode.size());
    for (JsonNode innerNode : arrayNode) {
        result.add(innerNode.textValue());
    }/*from  w w  w.j  av  a 2s .  c o  m*/
    return result;
}

From source file:mobile.vo.user.JobExp.java

public static JobExp create(JsonNode jobExpNode) {
    JobExp exp = new JobExp();
    exp.exp = Json.newObject();/*from   w  ww .j  a v a  2s .co  m*/

    exp.exp.put("beginYear", jobExpNode.hasNonNull("beginYear") ? jobExpNode.get("beginYear").asText() : "");
    exp.exp.put("beginMonth", jobExpNode.hasNonNull("beginMonth") ? jobExpNode.get("beginMonth").asText() : "");

    String endYear = jobExpNode.hasNonNull("endYear") ? jobExpNode.get("endYear").asText() : "";
    exp.exp.put("endYear", endYear.equals("") ? "-1" : endYear);
    exp.exp.put("endMonth", jobExpNode.hasNonNull("endMonth") ? jobExpNode.get("endMonth").asText() : "");

    exp.exp.put("company", jobExpNode.hasNonNull("company") ? jobExpNode.get("company").asText() : "");
    exp.exp.put("duty", jobExpNode.hasNonNull("duty") ? jobExpNode.get("duty").asText() : "");
    exp.exp.put("workInfo", jobExpNode.hasNonNull("workInfo") ? jobExpNode.get("workInfo").asText() : "");

    return exp;
}

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static List<Integer> integerListFromJsonNode(JsonNode node, String key) {
    if (node == null)
        return new ArrayList<Integer>(0);
    JsonNode value = node.get(key);
    if (value == null)
        return new ArrayList<Integer>(0);

    ArrayNode arrayNode = (ArrayNode) value;
    ArrayList<Integer> result = new ArrayList<Integer>(arrayNode.size());
    for (JsonNode innerNode : arrayNode) {
        result.add(innerNode.asInt());/*from w w  w . j a  v  a2s .c om*/
    }
    return result;
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java

public static boolean hasLine(String line, Context context) {
    boolean ret = false;
    String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
    JsonNode actualObj = Util.stringToJsonNode(bufferString);
    JsonNode lines = actualObj.get("lines");
    for (int i = 0; i < lines.size(); i++) {
        JsonNode lineJson = lines.get(i);
        if (lineJson.get("name").asText().equalsIgnoreCase(line)) {
            ret = true;//from  w w  w . j av  a2 s.c  o  m
            break;
        }
    }
    return ret;
}

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static String stringFromJsonNode(JsonNode node, String key, String defaultValue) {
    if (node == null)
        return defaultValue;
    JsonNode value = node.get(key);
    if (value == null)
        return defaultValue;
    return value.textValue();
}

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static double doubleFromJsonNode(JsonNode node, String key, double defaultValue) {
    if (node == null)
        return defaultValue;
    JsonNode value = node.get(key);
    if (value == null)
        return defaultValue;
    return value.asDouble();
}

From source file:com.pros.jsontransform.constraint.ConstraintValues.java

public static void validate(final JsonNode constraintNode, final JsonNode resultNode,
        final ObjectTransformer transformer) throws ObjectTransformerException {
    boolean found = false;
    JsonNode valuesArray = constraintNode.get(Constraint.$VALUES.toString());
    if (valuesArray.isArray()) {
        for (JsonNode valueNode : valuesArray) {
            if (resultNode.equals(valueNode)) {
                found = true;/*from www . ja  v  a2s.  c om*/
                break;
            }
        }
    }

    if (!found) {
        throw new ObjectTransformerException("Constraint violation [" + Constraint.$VALUES.toString() + "]"
                + " on transform node " + transformer.getTransformNodeFieldName());
    }
}

From source file:com.spoiledmilk.ibikecph.search.FoursquareData.java

public static double distance(Location loc, JsonNode jsonNode) {
    double ret = Double.MAX_VALUE;
    if (jsonNode.has("location") && jsonNode.get("location").has("lat")
            && jsonNode.get("location").has("lng")) {
        double latitude = jsonNode.get("location").get("lat").asDouble();
        double longitude = jsonNode.get("location").get("lng").asDouble();
        ret = loc.distanceTo(Util.locationFromCoordinates(latitude, longitude));
    }/*from   w  w  w .  j  a va2 s .  co  m*/
    return ret;
}

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static boolean booleanFromJsonNode(JsonNode node, String key, boolean defaultValue) {
    if (node == null)
        return defaultValue;
    JsonNode value = node.get(key);
    if (value == null)
        return defaultValue;
    return value.asBoolean();
}