use of com.fasterxml.jackson.core.TreeNode in project Gaffer by gchq.
the class RoaringBitmapJsonDeserialiser method deserialize.
@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");
}
}
use of com.fasterxml.jackson.core.TreeNode in project Gaffer by gchq.
the class HllSketchJsonDeserialiser method deserialize.
@Override
public HllSketch deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
final HllSketch hllp;
final TextNode jsonNodes = (TextNode) treeNode.get(HllSketchJsonConstants.BYTES);
if (isNull(jsonNodes)) {
final IntNode kNode = (IntNode) treeNode.get(HllSketchJsonConstants.LOG_K);
final int k = nonNull(kNode) ? kNode.asInt(DEFAULT_LOG_K) : DEFAULT_LOG_K;
hllp = new HllSketch(k);
} else {
hllp = HllSketch.heapify(jsonNodes.binaryValue());
}
final ArrayNode offers = (ArrayNode) treeNode.get(VALUES);
if (nonNull(offers)) {
for (final JsonNode offer : offers) {
if (nonNull(offer)) {
hllp.update(offer.asText());
}
}
}
return hllp;
}
use of com.fasterxml.jackson.core.TreeNode in project Gaffer by gchq.
the class HyperLogLogPlusJsonDeserialiser method deserialize.
@Override
public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
final TreeNode nestedHllp = treeNode.get("hyperLogLogPlus");
if (nonNull(nestedHllp)) {
treeNode = nestedHllp;
}
final HyperLogLogPlus hllp;
final TextNode jsonNodes = (TextNode) treeNode.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);
if (isNull(jsonNodes)) {
final IntNode pNode = (IntNode) treeNode.get("p");
final IntNode spNode = (IntNode) treeNode.get("sp");
final int p = nonNull(pNode) ? pNode.asInt(DEFAULT_P) : DEFAULT_P;
final int sp = nonNull(spNode) ? spNode.asInt(DEFAULT_SP) : DEFAULT_SP;
hllp = new HyperLogLogPlus(p, sp);
} else {
hllp = HyperLogLogPlus.Builder.build(jsonNodes.binaryValue());
}
final ArrayNode offers = (ArrayNode) treeNode.get("offers");
if (nonNull(offers)) {
for (final JsonNode offer : offers) {
if (nonNull(offer)) {
hllp.offer(offer.asText());
}
}
}
return hllp;
}
use of com.fasterxml.jackson.core.TreeNode in project snow-owl by b2ihealthcare.
the class ConceptPropertyDeserializer method deserialize.
@Override
public ConceptProperty<?> deserialize(JsonParser parser, DeserializationContext arg1) throws IOException, JsonProcessingException {
TreeNode node = parser.readValueAsTree();
ObjectCodec objectCodec = parser.getCodec();
Iterator<String> fieldNames = node.fieldNames();
PropertyType[] propertyTypes = PropertyType.values();
PropertyType propertyType = null;
while (fieldNames.hasNext()) {
String fieldName = (String) fieldNames.next();
if (fieldName.startsWith(VALUE_PREFIX)) {
String type = fieldName.replace(VALUE_PREFIX, "");
propertyType = Sets.newHashSet(propertyTypes).stream().filter(t -> t.getDisplayName().equalsIgnoreCase(type)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown property type '" + fieldName + "'."));
break;
}
}
if (propertyType == null) {
throw new IllegalArgumentException("Invalid property type with null value.");
}
switch(propertyType) {
case CODING:
return objectCodec.treeToValue(node, CodingConceptProperty.class);
case CODE:
return objectCodec.treeToValue(node, CodeConceptProperty.class);
case DATETIME:
return objectCodec.treeToValue(node, DateTimeConceptProperty.class);
case STRING:
return objectCodec.treeToValue(node, StringConceptProperty.class);
case BOOLEAN:
return objectCodec.treeToValue(node, BooleanConceptProperty.class);
case DECIMAL:
return objectCodec.treeToValue(node, DecimalConceptProperty.class);
case INTEGER:
return objectCodec.treeToValue(node, IntegerConceptProperty.class);
default:
throw new IllegalArgumentException("Unsupported property type '" + propertyType + "'.");
}
}
use of com.fasterxml.jackson.core.TreeNode in project snow-owl by b2ihealthcare.
the class ExtensionDeserializer method deserialize.
@Override
public Extension<?> deserialize(JsonParser parser, DeserializationContext ctx) throws IOException, JsonProcessingException {
TreeNode node = parser.readValueAsTree();
ObjectCodec objectCodec = parser.getCodec();
Iterator<String> fieldNames = node.fieldNames();
ExtensionType[] extensionTypes = ExtensionType.values();
ExtensionType extensionType = null;
while (fieldNames.hasNext()) {
String fieldName = (String) fieldNames.next();
if (fieldName.startsWith(VALUE_PREFIX)) {
String type = fieldName.replace(VALUE_PREFIX, "");
extensionType = Sets.newHashSet(extensionTypes).stream().filter(t -> t.getDisplayName().equalsIgnoreCase(type)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown extension type '" + fieldName + "'."));
break;
}
}
if (extensionType == null) {
throw new IllegalArgumentException("Invalid extension with null value type.");
}
switch(extensionType) {
case INTEGER:
return objectCodec.treeToValue(node, IntegerExtension.class);
case STRING:
return objectCodec.treeToValue(node, StringExtension.class);
default:
throw new IllegalArgumentException("Unsupported extension type '" + extensionType + "'.");
}
}
Aggregations