use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project snow-owl by b2ihealthcare.
the class ExpansionParameterDeserializer method deserialize.
@Override
public Parameter<?> deserialize(JsonParser parser, DeserializationContext arg1) throws IOException, JsonProcessingException {
TreeNode node = parser.readValueAsTree();
ObjectCodec objectCodec = parser.getCodec();
Iterator<String> fieldNames = node.fieldNames();
FhirDataType[] parameterTypes = FhirDataType.values();
FhirDataType parameterType = null;
while (fieldNames.hasNext()) {
String fieldName = (String) fieldNames.next();
if (fieldName.startsWith(VALUE_PREFIX)) {
parameterType = Sets.newHashSet(parameterTypes).stream().filter(t -> t.getSerializedName().equalsIgnoreCase(fieldName)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown expansion parameter type '" + fieldName + "'."));
break;
}
}
if (parameterType == null) {
throw new IllegalArgumentException("Invalid parameter type with null value.");
}
switch(parameterType) {
case URI:
return objectCodec.treeToValue(node, UriParameter.class);
case CODE:
return objectCodec.treeToValue(node, CodeParameter.class);
case DATETIME:
return objectCodec.treeToValue(node, DateTimeParameter.class);
case STRING:
return objectCodec.treeToValue(node, StringParameter.class);
case BOOLEAN:
return objectCodec.treeToValue(node, BooleanParameter.class);
case DECIMAL:
return objectCodec.treeToValue(node, DecimalParameter.class);
case INTEGER:
return objectCodec.treeToValue(node, IntegerParameter.class);
default:
throw new IllegalArgumentException("Unsupported property type '" + parameterType + "'.");
}
}
Aggregations