Search in sources :

Example 26 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project snow-owl by b2ihealthcare.

the class BundleEntryDeserializer method deserialize.

@Override
public Entry deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    TreeNode node = parser.readValueAsTree();
    ObjectCodec objectCodec = parser.getCodec();
    // Select the concrete class based on the resource type header
    TreeNode resourceTypeNode = node.path("resource").path("resourceType");
    if (resourceTypeNode instanceof TextNode) {
        TextNode textNode = (TextNode) resourceTypeNode;
        if (node.get("request") != null) {
            if (textNode.textValue().equals("Parameters")) {
                return objectCodec.treeToValue(node, ParametersRequestEntry.class);
            } else {
                return objectCodec.treeToValue(node, ResourceRequestEntry.class);
            }
        } else if (node.get("response") != null) {
            if (textNode.textValue().equals("Parameters")) {
                return objectCodec.treeToValue(node, ParametersResponseEntry.class);
            } else if (textNode.textValue().equals("OperationOutcome")) {
                return objectCodec.treeToValue(node, OperationOutcomeEntry.class);
            } else {
                return objectCodec.treeToValue(node, ResourceResponseEntry.class);
            }
        }
    }
    return objectCodec.treeToValue(node, RequestEntry.class);
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec)

Example 27 with TreeNode

use of com.fasterxml.jackson.core.TreeNode 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)

Example 28 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project snow-owl by b2ihealthcare.

the class UsageContextDeserializer method deserialize.

@Override
public UsageContext<?> deserialize(JsonParser parser, DeserializationContext arg1) throws IOException, JsonProcessingException {
    TreeNode node = parser.readValueAsTree();
    ObjectCodec objectCodec = parser.getCodec();
    Iterator<String> fieldNames = node.fieldNames();
    String valueFieldName = null;
    while (fieldNames.hasNext()) {
        String fieldName = (String) fieldNames.next();
        if (fieldName.startsWith(VALUE_PREFIX)) {
            valueFieldName = fieldName.replace(VALUE_PREFIX, "");
            break;
        }
    }
    if (valueFieldName == null) {
        throw new IllegalArgumentException("Invalid parameter type with null value.");
    }
    switch(valueFieldName) {
        case CodeableConceptUsageContext.CONTEXT_TYPE:
            return objectCodec.treeToValue(node, CodeableConceptUsageContext.class);
        case QuantityUsageContext.CONTEXT_TYPE:
            return objectCodec.treeToValue(node, QuantityUsageContext.class);
        case RangeUsageContext.CONTEXT_TYPE:
            return objectCodec.treeToValue(node, RangeUsageContext.class);
        default:
            throw new IllegalArgumentException("Unsupported useage context type '" + valueFieldName + "'.");
    }
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec)

Example 29 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project snow-owl by b2ihealthcare.

the class FhirResourceDeserializer method deserialize.

@Override
public FhirResource deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    TreeNode node = p.readValueAsTree();
    TreeNode resourceTypeNode = node.get("resourceType");
    if (resourceTypeNode instanceof TextNode) {
        TextNode resourceTypeTextNode = (TextNode) resourceTypeNode;
        switch(resourceTypeTextNode.textValue()) {
            case CodeSystem.RESOURCE_TYPE_CODE_SYSTEM:
                return p.getCodec().treeToValue(node, CodeSystem.class);
            case ValueSet.RESOURCE_TYPE_VALUE_SET:
                return p.getCodec().treeToValue(node, ValueSet.class);
            case ConceptMap.RESOURCE_TYPE_CONCEPT_MAP:
                return p.getCodec().treeToValue(node, ConceptMap.class);
            case StructureDefinition.RESOURCE_TYPE_STRUCTURE_DEFINITION:
                return p.getCodec().treeToValue(node, StructureDefinition.class);
            case Bundle.RESOURCE_TYPE_BUNDLE:
                return p.getCodec().treeToValue(node, Bundle.class);
            case OperationOutcome.RESOURCE_TYPE_OPERATION_OUTCOME:
                return p.getCodec().treeToValue(node, OperationOutcome.class);
            default:
                break;
        }
    }
    throw new IllegalArgumentException("Unknown resource type for '" + node.toString() + "'.");
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 30 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project snow-owl by b2ihealthcare.

the class FhirBatchRequestProcessor method processClientErrorException.

private void processClientErrorException(ArrayNode arrayNode, HttpClientErrorException hcee) throws JsonMappingException, JsonProcessingException {
    // HttpClientErrorException can return an OperationOutcome in the response body
    ObjectNode resourceNode = (ObjectNode) objectMapper.readTree(hcee.getResponseBodyAsString());
    TreeNode resourceTypeNode = resourceNode.path("resource").path("resourceType");
    if (resourceTypeNode instanceof TextNode) {
        TextNode textNode = (TextNode) resourceTypeNode;
        if (textNode.textValue().equals("OperationOutcome")) {
            addResponse(arrayNode, resourceNode, String.valueOf(hcee.getStatusCode().value()));
            return;
        }
    }
    processHttpException(arrayNode, hcee);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Aggregations

TreeNode (com.fasterxml.jackson.core.TreeNode)34 TextNode (com.fasterxml.jackson.databind.node.TextNode)11 JsonParser (com.fasterxml.jackson.core.JsonParser)10 IOException (java.io.IOException)8 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 HashMap (java.util.HashMap)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)4 BsonParser (de.undercouch.bson4jackson.BsonParser)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)3 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Sets (com.google.common.collect.Sets)3 Iterator (java.util.Iterator)3 Test (org.junit.Test)3 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2