@Override public RoaringBitmap deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser); final TreeNode bitmapObject = treeNode.get(RoaringBitmapConstants.BITMAP_WRAPPER_OBJECT_NAME); if (null != bitmapObject) { final TextNode jsonNodes = (TextNode) bitmapObject.get(RoaringBitmapConstants.BITMAP_VALUE_FIELD_NAME); return (RoaringBitmap) bitmapSerialiser.deserialise(jsonNodes.binaryValue()); } else { throw new IllegalArgumentException("Received null bitmap treenode"); } }
public TreeNode get(final String path) { if (!path.isEmpty()) { for (TreeNode treeNode : treeNodes) { if (path.startsWith(treeNode.getId())) { return treeNode.get(path.substring(...)); } } } return this; }
@Override public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser); final TreeNode coreHyperLogLogPlusObject = treeNode.get("hyperLogLogPlus"); if (null != coreHyperLogLogPlusObject) { final TextNode jsonNodes = (TextNode) coreHyperLogLogPlusObject.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD); final byte[] nodeAsString = jsonNodes.binaryValue(); final HyperLogLogPlus hyperLogLogPlus = HyperLogLogPlus.Builder.build(nodeAsString); return hyperLogLogPlus; } else { throw new IllegalArgumentException("Receieved null or empty HyperLogLogPlus sketch"); } } }
@Override public CoinbaseProCandle deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); TreeNode jo = mapper.readTree(jp); if (!jo.isArray() || jo.size() != 6) { throw new JsonMappingException(jp, "An array of length 6 expected: " + jo.toString()); } for (int i = 0; i < 6; i++) { if (!(jo.get(i) instanceof NumericNode)) { throw new JsonMappingException(jp, "Numeric values expected: " + jo.toString()); } } return new CoinbaseProCandle( new Date(((NumericNode) jo.get(0)).asLong() * 1000), new BigDecimal(((NumericNode) jo.get(3)).asText()), new BigDecimal(((NumericNode) jo.get(2)).asText()), new BigDecimal(((NumericNode) jo.get(1)).asText()), new BigDecimal(((NumericNode) jo.get(4)).asText()), new BigDecimal(((NumericNode) jo.get(5)).asText())); } }
public class StringValueDeserializer extends JsonDeserializer<String>{ @Override public String deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec codec = parser.getCodec(); TreeNode node = codec.readTree(parser); JsonNode value = (JsonNode)node.get("value"); if (value != null){ return value.asText(); } return null; } }
@Override public Icon deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { TreeNode jsonNode = p.getCodec().readTree(p); String cssClass = ((TextNode) jsonNode.get("cssClass")).asText(); return () -> cssClass; }
@Override public Icon deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { TreeNode jsonNode = p.getCodec().readTree(p); String cssClass = ((TextNode) jsonNode.get("cssClass")).asText(); return () -> cssClass; }
@Override public Icon deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { TreeNode jsonNode = p.getCodec().readTree(p); String cssClass = ((TextNode) jsonNode.get("cssClass")).asText(); return () -> cssClass; }
@Override public RoaringBitmap deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser); final TreeNode bitmapObject = treeNode.get(RoaringBitmapConstants.BITMAP_WRAPPER_OBJECT_NAME); if (null != bitmapObject) { final TextNode jsonNodes = (TextNode) bitmapObject.get(RoaringBitmapConstants.BITMAP_VALUE_FIELD_NAME); return (RoaringBitmap) bitmapSerialiser.deserialise(jsonNodes.binaryValue()); } else { throw new IllegalArgumentException("Received null bitmap treenode"); } }
private String value(TreeNode node) throws IOException, JsonParseException { TextNode value = (TextNode) node.get(QUOTA_ROOT_VALUE_FIELD); return value.asText(); }
JsonParser p = ...; ObjectCodec codec = p.getCodec(); TreeNode node = p.readValueAsTree(); Map<String, String> childToParentIds = codec.treeAsTokens(node.get("childToParent")).readValueAs( new TypeReference<Map<String, String>>() { });
@Override public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser); final TreeNode coreHyperLogLogPlusObject = treeNode.get("hyperLogLogPlus"); if (null != coreHyperLogLogPlusObject) { final TextNode jsonNodes = (TextNode) coreHyperLogLogPlusObject.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD); final byte[] nodeAsString = jsonNodes.binaryValue(); final HyperLogLogPlus hyperLogLogPlus = HyperLogLogPlus.Builder.build(nodeAsString); return hyperLogLogPlus; } else { throw new IllegalArgumentException("Receieved null or empty HyperLogLogPlus sketch"); } } }
protected Class<?> determineConcreteType(TreeNode node) { TreeNode entityNode = node.get(ConstantsV1.ENTITY_TYPE); if (entityNode != null && entityNode.isValueNode()) { String entityType = ((ValueNode) entityNode).asText(); Class<?> klazz = NuxeoConverterFactory.entityTypeToClass.get(entityType); if (klazz != null) { return klazz; } } return Object.class; }
private Optional<Domain> domain(TreeNode node) throws IOException, JsonParseException { TreeNode value = node.get(QUOTA_ROOT_DOMAIN_FIELD); if (value == null || value.isMissingNode()) { return Optional.empty(); } return Optional.ofNullable(node.asToken().asString()).map(Domain::of); }
@Override public ContentAndMetadata deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser); Preconditions.checkState(treeNode.isArray() && treeNode.size() >= 1, "The response should be an array with at least one element"); Preconditions.checkState(treeNode.get(0).isObject(), "The element should be a Json object"); ObjectNode node = (ObjectNode) treeNode.get(0); return ContentAndMetadata.from(ImmutableList.copyOf(node.fields()) .stream() .collect(Guavate.toImmutableMap(Entry::getKey, entry -> asListOfString(entry.getValue())))); }
@Override public FieldPatch<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { final TreeNode node = p.readValueAsTree(); final TreeNode setNode = node.get("value"); final Object value = setNode != null ? p.getCodec().treeToValue(setNode, valueType) : null; return FieldPatch.nullableOf(value); } }
@Override @SuppressWarnings("deprecation") public ObjectId deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { if (jp instanceof BsonParser) { BsonParser bsonParser = (BsonParser)jp; if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_OBJECTID) { throw ctxt.mappingException(ObjectId.class); } return (ObjectId)bsonParser.getEmbeddedObject(); } else { TreeNode tree = jp.getCodec().readTree(jp); int time = ((ValueNode)tree.get("$time")).asInt(); int machine = ((ValueNode)tree.get("$machine")).asInt(); int inc = ((ValueNode)tree.get("$inc")).asInt(); return new ObjectId(time, machine, inc); } } }
@Override @SuppressWarnings("deprecation") public Timestamp deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { if (jp instanceof BsonParser) { BsonParser bsonParser = (BsonParser)jp; if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_TIMESTAMP) { throw ctxt.mappingException(Timestamp.class); } return (Timestamp)bsonParser.getEmbeddedObject(); } else { TreeNode tree = jp.getCodec().readTree(jp); int time = ((ValueNode)tree.get("$time")).asInt(); int inc = ((ValueNode)tree.get("$inc")).asInt(); return new Timestamp(time, inc); } } }