Search in sources :

Example 46 with DeserializationContext

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 + "'.");
    }
}
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

DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)27 JsonParser (com.fasterxml.jackson.core.JsonParser)20 IOException (java.io.IOException)17 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)7 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)7 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)6 Map (java.util.Map)6 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)5 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)5 ObjectNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Iterator (java.util.Iterator)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)3