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