Search in sources :

Example 96 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode 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 97 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode 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 98 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode 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)

Example 99 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project Rosetta by HubSpot.

the class StoredAsJsonTest method itHandlesSubTypes.

@Test
public void itHandlesSubTypes() throws JsonProcessingException {
    ConcreteStoredAsJsonList typeInfoBean = new ConcreteStoredAsJsonList();
    typeInfoBean.setInnerBeans(Collections.singletonList(inner));
    TextNode expectedList = TextNode.valueOf("[{\"stringProperty\":\"value\"}]");
    JsonNode node = Rosetta.getMapper().valueToTree(typeInfoBean);
    assertThat(node.get("innerBeans")).isEqualTo(expectedList);
    assertThat(Rosetta.getMapper().treeToValue(node, StoredAsJsonListTypeInfoBean.class).getInnerBeans().get(0).getStringProperty()).isEqualTo("value");
    assertThat(Rosetta.getMapper().treeToValue(node, ConcreteStoredAsJsonList.class).getInnerBeans().get(0).getStringProperty()).isEqualTo("value");
}
Also used : StoredAsJsonListTypeInfoBean(com.hubspot.rosetta.beans.StoredAsJsonListTypeInfoBean) ConcreteStoredAsJsonList(com.hubspot.rosetta.beans.StoredAsJsonListTypeInfoBean.ConcreteStoredAsJsonList) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 100 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesDate.

@Test
public void applyGeneratesDate() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "string");
    TextNode formatNode = TextNode.valueOf("date-time");
    objectNode.set("format", formatNode);
    JType mockDateType = mock(JType.class);
    FormatRule mockFormatRule = mock(FormatRule.class);
    when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), any(), Mockito.isA(JType.class), isNull())).thenReturn(mockDateType);
    when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);
    JType result = rule.apply("fooBar", objectNode, null, jpackage, null);
    assertThat(result, equalTo(mockDateType));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)140 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)48 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)37 Test (org.junit.Test)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 IntNode (com.fasterxml.jackson.databind.node.IntNode)16 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)15 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)12 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 TreeNode (com.fasterxml.jackson.core.TreeNode)11 HashMap (java.util.HashMap)11 List (java.util.List)11 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 Map (java.util.Map)10