use of com.b2international.snowowl.fhir.core.codesystems.ExtensionType 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