Example usage for com.fasterxml.jackson.databind.node ObjectNode get

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get

Introduction

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

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:com.redhat.lightblue.query.ForEachExpression.java

/**
 * Parses a foreach expression from the given json object
 *///from ww w .j  a v  a  2  s  . c  o  m
public static ForEachExpression fromJson(ObjectNode node) {
    if (node.size() == 1) {
        JsonNode argNode = node.get("$foreach");
        if (argNode instanceof ObjectNode) {
            ObjectNode objArg = (ObjectNode) argNode;
            if (objArg.size() == 2) {
                JsonNode updateNode = null;
                JsonNode queryNode = null;
                Path field = null;
                for (Iterator<Map.Entry<String, JsonNode>> itr = objArg.fields(); itr.hasNext();) {
                    Map.Entry<String, JsonNode> entry = itr.next();
                    if ("$update".equals(entry.getKey())) {
                        updateNode = entry.getValue();
                    } else {
                        field = new Path(entry.getKey());
                        queryNode = entry.getValue();
                    }
                }
                if (queryNode != null && updateNode != null && field != null) {
                    return new ForEachExpression(field, UpdateQueryExpression.fromJson(queryNode),
                            ForEachUpdateExpression.fromJson(updateNode));
                }
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString());
}

From source file:com.mirth.connect.client.ui.components.rsta.AutoCompleteProperties.java

static AutoCompleteProperties fromJSON(String autoCompleteJSON) {
    Boolean activateAfterLetters = null;
    String activateAfterOthers = null;
    Integer activationDelay = null;

    if (StringUtils.isNotBlank(autoCompleteJSON)) {
        try {//from  www . jav a2 s .  c  o m
            ObjectMapper mapper = new ObjectMapper();
            ObjectNode rootNode = (ObjectNode) mapper.readTree(autoCompleteJSON);

            JsonNode node = rootNode.get("activateAfterLetters");
            if (node != null) {
                activateAfterLetters = node.asBoolean();
            }

            node = rootNode.get("activateAfterOthers");
            if (node != null) {
                activateAfterOthers = node.asText();
            }

            node = rootNode.get("activationDelay");
            if (node != null) {
                activationDelay = node.asInt();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return new AutoCompleteProperties(activateAfterLetters, activateAfterOthers, activationDelay);
}

From source file:com.pros.jsontransform.expression.FunctionAppendArrayIndex.java

public static JsonNode evaluate(final JsonNode argsNode, final JsonNode valueNode,
        final ObjectTransformer transformer) throws ObjectTransformerException {
    List<Integer> sourceArrayIndexes = transformer.getSourceArrayIndexes();
    ObjectNode resultNode = (ObjectNode) argsNode;
    resultNode.put("returnValue",
            transformValue(valueNode, transformer) + sourceArrayIndexes.get(sourceArrayIndexes.size() - 1));

    return resultNode.get("returnValue");
}

From source file:com.pros.jsontransform.expression.FunctionAppend.java

public static JsonNode evaluate(final JsonNode argsNode, final JsonNode valueNode,
        final ObjectTransformer transformer) throws ObjectTransformerException {
    ObjectNode resultNode = (ObjectNode) argsNode;
    resultNode.put("returnValue", transformValue(valueNode, transformer)
            + transformArgument(argsNode.path(ARGUMENT_WHAT), transformer).asText());

    return resultNode.get("returnValue");
}

From source file:com.google.api.server.spi.tools.GenClientLibAction.java

private static boolean isRestDiscoveryDoc(String discoveryDoc) throws IOException {
    ObjectNode discoveryJson = ObjectMapperUtil.createStandardObjectMapper().readValue(discoveryDoc,
            ObjectNode.class);
    return "rest".equals(discoveryJson.get("protocol").asText());
}

From source file:org.glowroot.benchmark.ResultFormatter.java

private static double getAllocatedBytes(JsonNode result) {
    ObjectNode secondaryMetrics = (ObjectNode) result.get("secondaryMetrics");
    if (secondaryMetrics == null) {
        return -1;
    }//from w  w w .j av a2s .  c  o  m
    ObjectNode gcAllocRateNorm = (ObjectNode) secondaryMetrics.get("\u00b7gc.alloc.rate.norm");
    if (gcAllocRateNorm == null) {
        return -1;
    }
    return gcAllocRateNorm.get("score").asDouble();
}

From source file:com.redhat.lightblue.query.ArrayAddExpression.java

/**
 * Parses an array update expression using the given json object
 *///from w  w w  .  j a  v a 2s. c  om
public static ArrayAddExpression fromJson(ObjectNode node) {
    if (node.size() == 1) {
        UpdateOperator op = UpdateOperator._append;
        JsonNode arg = node.get(UpdateOperator._append.toString());
        if (arg == null) {
            arg = node.get(UpdateOperator._insert.toString());
            op = UpdateOperator._insert;
        }
        if (arg instanceof ObjectNode) {
            ObjectNode objArg = (ObjectNode) arg;
            if (objArg.size() == 1) {
                Map.Entry<String, JsonNode> item = objArg.fields().next();
                Path field = new Path(item.getKey());
                JsonNode valueNode = item.getValue();
                List<RValueExpression> rvalues = new ArrayList<>();
                if (valueNode instanceof ArrayNode) {
                    for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) {
                        rvalues.add(RValueExpression.fromJson(itr.next()));
                    }
                } else {
                    rvalues.add(RValueExpression.fromJson(valueNode));
                }
                return new ArrayAddExpression(field, op, rvalues);
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString());
}

From source file:com.redhat.lightblue.query.SortKey.java

public static SortKey fromJson(ObjectNode node) {
    if (node.size() != 1) {
        throw Error.get(QueryConstants.ERR_INVALID_SORT, node.toString());
    }//w w w. j  av  a  2s  .  c o m
    String fieldString = node.fieldNames().next();
    String dir = node.get(fieldString).asText();
    Path field = new Path(fieldString);
    boolean desc = false;
    switch (dir) {
    case "$asc":
        desc = false;
        break;
    case "$desc":
        desc = true;
        break;
    default:
        throw Error.get(QueryConstants.ERR_INVALID_SORT, node.toString());
    }
    return new SortKey(field, desc);
}

From source file:org.gitana.platform.client.util.DriverUtil.java

public static List<String> toStringList(Response response) {
    List<String> list = new ArrayList<String>();

    ObjectNode objectNode = response.getObjectNode();
    ArrayNode rows = (ArrayNode) objectNode.get("rows");
    for (int i = 0; i < rows.size(); i++) {
        list.add(rows.get(i).textValue());
    }// w w w  .  j  av  a 2 s  . c o m

    return list;
}

From source file:com.collective.celos.Util.java

public static String getStringProperty(ObjectNode properties, String name) {
    JsonNode node = properties.get(name);
    if (node == null) {
        throw new IllegalArgumentException("Property " + name + " not set.");
    } else if (!node.isTextual()) {
        throw new IllegalArgumentException("Property " + name + " is not a string, but " + node);
    } else {/*  w  w w  . jav a 2 s  . com*/
        return node.textValue();
    }
}