use of com.fasterxml.jackson.databind.node.BinaryNode in project jackson-databind by FasterXML.
the class TestTreeTraversingParser method testBinaryNode.
public void testBinaryNode() throws Exception {
byte[] inputBinary = new byte[] { 0, -5 };
BinaryNode n = new BinaryNode(inputBinary);
JsonParser p = n.traverse();
assertNull(p.getCurrentToken());
// exposed as POJO... not as VALUE_STRING
assertToken(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken());
byte[] data = p.getBinaryValue();
assertNotNull(data);
assertArrayEquals(inputBinary, data);
// but as importantly, can be viewed as base64 encoded thing:
assertEquals("APs=", p.getText());
assertNull(p.nextToken());
p.close();
}
use of com.fasterxml.jackson.databind.node.BinaryNode in project lucene-solr by apache.
the class SmileWriterTest method getVal.
public static Object getVal(JsonNode value) {
if (value instanceof NullNode) {
return null;
}
if (value instanceof NumericNode) {
return ((NumericNode) value).numberValue();
}
if (value instanceof BooleanNode) {
((BooleanNode) value).booleanValue();
}
if (value instanceof ObjectNode) {
Iterator<Map.Entry<String, JsonNode>> it = ((ObjectNode) value).fields();
Map result = new LinkedHashMap<>();
while (it.hasNext()) {
Map.Entry<String, JsonNode> e = it.next();
result.put(e.getKey(), getVal(e.getValue()));
}
return result;
}
if (value instanceof ArrayNode) {
ArrayList result = new ArrayList();
Iterator<JsonNode> it = ((ArrayNode) value).elements();
while (it.hasNext()) {
result.add(getVal(it.next()));
}
return result;
}
if (value instanceof BinaryNode) {
return ((BinaryNode) value).binaryValue();
}
return value.textValue();
}
Aggregations