Search in sources :

Example 1 with FhirDataType

use of com.b2international.snowowl.fhir.core.model.dt.FhirDataType 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 + "'.");
    }
}
Also used : StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) TreeNode(com.fasterxml.jackson.core.TreeNode) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) Iterator(java.util.Iterator) JsonParser(com.fasterxml.jackson.core.JsonParser) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) FhirDataType(com.b2international.snowowl.fhir.core.model.dt.FhirDataType) Sets(com.google.common.collect.Sets) TreeNode(com.fasterxml.jackson.core.TreeNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) FhirDataType(com.b2international.snowowl.fhir.core.model.dt.FhirDataType)

Aggregations

FhirDataType (com.b2international.snowowl.fhir.core.model.dt.FhirDataType)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 TreeNode (com.fasterxml.jackson.core.TreeNode)1 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)1 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1