Example usage for com.fasterxml.jackson.databind.node MissingNode getInstance

List of usage examples for com.fasterxml.jackson.databind.node MissingNode getInstance

Introduction

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

Prototype

public static MissingNode getInstance() 

Source Link

Usage

From source file:io.orchestrate.client.RelationResource.java

private static JsonNode parseJson(final String json, final ObjectMapper mapper) throws IOException {
    assert (mapper != null);

    try {/* www.java 2s  .co  m*/
        if (json != null) {
            return mapper.readTree(json);
        }
    } catch (final JsonMappingException ignored) {
    }
    return MissingNode.getInstance();
}

From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ObjectKeyExpressionEvaluator.java

private JRJsonNode goDeeperIntoObjectNode(JRJsonNode jrJsonNode, boolean keepMissingNode) {
    ObjectNode dataNode = (ObjectNode) jrJsonNode.getDataNode();
    ArrayNode container = getEvaluationContext().getObjectMapper().createArrayNode();

    // A complex expression allows an object key to treated as a REGEX
    if (expression.isComplex()) {
        Iterator<String> fieldNamesIterator = dataNode.fieldNames();
        while (fieldNamesIterator.hasNext()) {
            String fieldName = fieldNamesIterator.next();
            Matcher fieldNameMatcher = fieldNamePattern.matcher(fieldName);

            if (fieldNameMatcher.matches()) {
                JsonNode deeperNode = dataNode.path(fieldName);

                // if the deeper node is object/value => filter and add it
                if (deeperNode.isObject() || deeperNode.isValueNode() || deeperNode.isArray()) {

                    JRJsonNode child = jrJsonNode.createChild(deeperNode);
                    if (applyFilter(child)) {
                        container.add(deeperNode);
                    }//from   w  w  w  .  jav a2  s.com
                }
            }
        }
    } else {
        JsonNode deeperNode = dataNode.path(expression.getObjectKey());

        // if the deeper node is object/value => filter and add it
        if (deeperNode.isObject() || deeperNode.isValueNode() || deeperNode.isArray()) {

            JRJsonNode child = jrJsonNode.createChild(deeperNode);
            if (applyFilter(child)) {
                container.add(deeperNode);
            }
        }
    }

    if (container.size() > 1) {
        return jrJsonNode.createChild(container);
    } else if (container.size() == 1) {
        return jrJsonNode.createChild(container.get(0));
    }
    // Filtering expressions need the missing node to check for null
    else if (keepMissingNode) {
        return jrJsonNode.createChild(MissingNode.getInstance());
    }

    return null;
}

From source file:de.jlo.talendcomp.json.JsonDocument.java

/**
 * returns the node start from the root//from  w  w w  . j a va 2  s. c  o m
 * @param jsonPath
 * @return node or null if nothing found or a MissingNode was found
 */
public JsonNode getNodeIncludeMissing(String jsonPath) {
    try {
        JsonPath compiledPath = getCompiledJsonPath(jsonPath);
        JsonNode node = rootContext.read(compiledPath);
        if (node.isNull()) {
            return null;
        } else {
            return node;
        }
    } catch (PathNotFoundException e) {
        return MissingNode.getInstance();
    }
}

From source file:de.jlo.talendcomp.json.JsonDocument.java

/**
 * Retrieves with real JSONPath the nodes starting from the given node
 * @param parentNode/*w w  w  .  j  a  v  a2  s  .c o  m*/
 * @param jsonPath
 * @return an ArrayNode with the search result
 */
public JsonNode getNodeIncludeMissing(JsonNode parentNode, String jsonPath) {
    if (jsonPath == null || jsonPath.trim().isEmpty()) {
        throw new IllegalArgumentException("jsonPath cannot be null or empty");
    }
    if (parentNode == null) {
        throw new IllegalArgumentException("parentNode cannot be null");
    }
    if (parentNode == rootNode || jsonPath.startsWith("$")) {
        return getNodeIncludeMissing(jsonPath);
    }
    if (jsonPath.equals(".")) {
        return parentNode;
    }
    ParseContext parseContext = JsonPath.using(JACKSON_JSON_NODE_CONFIGURATION);
    DocumentContext context = parseContext.parse(parentNode);
    // fake a root path but use a arbitrary node as fake root
    JsonPath compiledPath = getCompiledJsonPath(jsonPath);
    JsonNode node = null;
    try {
        node = context.read(compiledPath);
        if (node.isNull()) {
            return null;
        } else {
            return node;
        }
    } catch (PathNotFoundException e) {
        return MissingNode.getInstance();
    }
}