List of usage examples for com.fasterxml.jackson.databind.node ValueNode textValue
public String textValue()
From source file:com.redhat.lightblue.util.JsonUtils.java
/** * Returns a Java object for a json value node based on the node type. *//*from w ww. j ava 2 s. com*/ public static Object valueFromJson(ValueNode node) { if (node instanceof NullNode) { return null; } else { if (node instanceof TextNode) { return node.textValue(); } else if (node instanceof BooleanNode) { return node.booleanValue(); } else if (node instanceof NumericNode) { return node.numberValue(); } else { throw new RuntimeException("Unsupported node type:" + node.getClass().getName()); } } }
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 ww w . j a va 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()); } }