use of com.b2international.snowowl.fhir.core.codesystems.PropertyType 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 + "'.");
}
}
Aggregations