Java Code Examples for com.fasterxml.jackson.core.TreeNode#isValueNode()
The following examples show how to use
com.fasterxml.jackson.core.TreeNode#isValueNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONParser.java From Halyard with Apache License 2.0 | 5 votes |
private void hash(TreeNode node) { if (node.isArray()) { md.update((byte)'l'); for (int i = 0; i < node.size(); i++) { hash(node.get(i)); } md.update((byte)'e'); } else if (node.isObject()) { String[] fieldNames = new String[node.size()]; Iterator<String> it = node.fieldNames(); for (int i=0; i< fieldNames.length; i++) { fieldNames[i] = it.next(); } Arrays.sort(fieldNames); md.update((byte)'d'); for (String fName : fieldNames) { hash(fName); hash(node.get(fName)); } md.update((byte)'e'); } else if (node.isValueNode()) { String val = ((JsonNode)node).textValue(); if (val != null) { hash(val); } } else { throw new IllegalArgumentException(node.toString()); } }
Example 2
Source File: DurationSerialization.java From heroic with Apache License 2.0 | 5 votes |
private Duration deserializeObject(TreeNode tree, DeserializationContext c) throws JsonMappingException { if (tree == null) { throw c.mappingException("expected object"); } TreeNode node; ValueNode valueNode; final long duration; final TimeUnit unit; if ((node = tree.get("duration")) != null && node.isValueNode() && (valueNode = (ValueNode) node).isNumber()) { duration = valueNode.asLong(); } else { throw c.mappingException("duration is not a numeric field"); } if ((node = tree.get("unit")) != null && node.isValueNode() && (valueNode = (ValueNode) node).isTextual()) { unit = TimeUnit.valueOf(valueNode.asText().toUpperCase()); } else { unit = Duration.DEFAULT_UNIT; } return new Duration(duration, unit); }