Java Code Examples for com.fasterxml.jackson.databind.JsonNode#binaryValue()
The following examples show how to use
com.fasterxml.jackson.databind.JsonNode#binaryValue() .
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: RangeBoundValueDeserializer.java From presto with Apache License 2.0 | 6 votes |
private Object toValue(JsonNode node) throws IOException { if (node.isTextual()) { return node.asText(); } else if (node.isNumber()) { return node.numberValue(); } else if (node.isBoolean()) { return node.asBoolean(); } else if (node.isBinary()) { return node.binaryValue(); } else { throw new IllegalStateException("Unexpected range bound value: " + node); } }
Example 2
Source File: DynamoDSETranslatorJSONBlob.java From dynamo-cassandra-proxy with Apache License 2.0 | 6 votes |
private Object getObjectFromJsonLeaf(Map.Entry<String, JsonNode> leaf) { DynamoDBAttributeType key = valueOf(leaf.getKey()); JsonNode value = leaf.getValue(); try { switch (key) { case N: return value.asDouble(); case S: return value.asText(); case BOOL: return value.asBoolean(); case B: return value.binaryValue(); default: logger.error("Type not supported"); break; } return null; } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return null; } }
Example 3
Source File: ActorObjectSerializer.java From java-sdk with MIT License | 6 votes |
/** * Extracts the response data from a JSON Payload where data is in "data" attribute. * * @param payload JSON payload containing "data". * @return byte[] instance, null. * @throws IOException In case it cannot generate String. */ public byte[] unwrapData(final byte[] payload) throws IOException { if (payload == null) { return null; } JsonNode root = OBJECT_MAPPER.readTree(payload); if (root == null) { return null; } JsonNode dataNode = root.get("data"); if (dataNode == null) { return null; } return dataNode.binaryValue(); }
Example 4
Source File: TreeTraversingParser.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException, JsonParseException { // Multiple possibilities... JsonNode n = currentNode(); if (n != null) { // binary node? byte[] data = n.binaryValue(); // (or TextNode, which can also convert automatically!) if (data != null) { return data; } // Or maybe byte[] as POJO? if (n.isPojo()) { Object ob = ((POJONode) n).getPojo(); if (ob instanceof byte[]) { return (byte[]) ob; } } } // otherwise return null to mark we have no binary content return null; }
Example 5
Source File: PartitionData.java From presto with Apache License 2.0 | 5 votes |
public static Object getValue(JsonNode partitionValue, Type type) { if (partitionValue.isNull()) { return null; } switch (type.typeId()) { case BOOLEAN: return partitionValue.asBoolean(); case INTEGER: case DATE: return partitionValue.asInt(); case LONG: case TIMESTAMP: return partitionValue.asLong(); case FLOAT: return partitionValue.floatValue(); case DOUBLE: return partitionValue.doubleValue(); case STRING: case UUID: return partitionValue.asText(); case FIXED: case BINARY: try { return partitionValue.binaryValue(); } catch (IOException e) { throw new UncheckedIOException("Failed during JSON conversion of " + partitionValue, e); } case DECIMAL: return partitionValue.decimalValue(); } throw new UnsupportedOperationException("Type not supported as partition column: " + type); }
Example 6
Source File: JsonCacheImpl.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public Object get(JsonPointer ptr) throws CacheException { Object result; if (root == null) { result = null; } else { try { JsonNode node = root.at(ptr); switch (node.getNodeType()) { case ARRAY: case OBJECT: result = node; break; case BINARY: result = node.binaryValue(); break; case BOOLEAN: result = node.booleanValue(); break; case NUMBER: result = node.numberValue(); break; case POJO: result = ((POJONode) node).getPojo(); break; case STRING: result = node.textValue(); break; default: result = null; break; } } catch (IOException e) { throw new CacheException(e); } } return result; }
Example 7
Source File: JacksonUtil.java From webauthn4j with Apache License 2.0 | 5 votes |
public static byte[] binaryValue(JsonNode jsonNode) { try { return jsonNode.binaryValue(); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example 8
Source File: JsonConvert.java From DBus with Apache License 2.0 | 5 votes |
@Override public Object convert(Schema schema, JsonNode value) { try { return value.binaryValue(); } catch (IOException e) { throw new DataException("Invalid bytes field", e); } }
Example 9
Source File: RangeBoundValueDeserializer.java From presto-kudu with Apache License 2.0 | 5 votes |
private Object toValue(JsonNode node) throws IOException { if (node.isTextual()) { return node.asText(); } else if (node.isNumber()) { return node.numberValue(); } else if (node.isBoolean()) { return node.asBoolean(); } else if (node.isBinary()) { return node.binaryValue(); } else { throw new IllegalStateException("Unexpected range bound value: " + node); } }
Example 10
Source File: JsonFileReader.java From kafka-connect-fs with Apache License 2.0 | 4 votes |
private Object mapValue(Schema schema, JsonNode value) { if (value == null) return null; switch (value.getNodeType()) { case BOOLEAN: return value.booleanValue(); case NUMBER: if (value.isShort()) { return value.shortValue(); } else if (value.isInt()) { return value.intValue(); } else if (value.isLong()) { return value.longValue(); } else if (value.isFloat()) { return value.floatValue(); } else if (value.isDouble()) { return value.doubleValue(); } else if (value.isBigInteger()) { return value.bigIntegerValue(); } else { return value.numberValue(); } case STRING: return value.asText(); case BINARY: try { return value.binaryValue(); } catch (IOException ioe) { throw new RuntimeException(ioe); } case OBJECT: case POJO: Struct struct = new Struct(schema); Iterable<Map.Entry<String, JsonNode>> fields = value::fields; StreamSupport.stream(fields.spliterator(), false) .forEach(field -> struct.put(field.getKey(), mapValue(extractSchema(field.getValue()), field.getValue())) ); return struct; case ARRAY: Iterable<JsonNode> arrayElements = value::elements; return StreamSupport.stream(arrayElements.spliterator(), false) .map(elm -> mapValue(schema, elm)) .collect(Collectors.toList()); case NULL: case MISSING: default: return null; } }