Example usage for com.fasterxml.jackson.databind.node ValueNode toString

List of usage examples for com.fasterxml.jackson.databind.node ValueNode toString

Introduction

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

Prototype

public String toString() 

Source Link

Usage

From source file:com.discover.cls.processors.cls.JSONToAttributes.java

private void addKeys(final String currentPath, final JsonNode jsonNode, final String separator,
        final boolean preserveType, final boolean flattenArrays, final Map<String, String> map) {
    if (jsonNode.isObject()) {
        ObjectNode objectNode = (ObjectNode) jsonNode;
        Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
        String pathPrefix = currentPath.isEmpty() ? "" : currentPath + separator;

        while (iter.hasNext()) {
            Map.Entry<String, JsonNode> entry = iter.next();
            addKeys(pathPrefix + entry.getKey(), entry.getValue(), separator, preserveType, flattenArrays, map);
        }/*from w w  w .  j a  v a  2  s.  c  om*/
    } else if (jsonNode.isArray()) {
        if (flattenArrays) {
            ArrayNode arrayNode = (ArrayNode) jsonNode;
            for (int i = 0; i < arrayNode.size(); i++) {
                addKeys(currentPath + "[" + i + "]", arrayNode.get(i), separator, preserveType, flattenArrays,
                        map);
            }
        } else {
            map.put(currentPath, jsonNode.toString());
        }
    } else if (jsonNode.isValueNode()) {
        ValueNode valueNode = (ValueNode) jsonNode;
        map.put(currentPath,
                valueNode.isTextual() && preserveType ? valueNode.toString() : valueNode.textValue());
    }
}