Search in sources :

Example 1 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project flink by apache.

the class JsonGeneratorTest method testGeneratorWithoutAnyAttachements.

@Test
public void testGeneratorWithoutAnyAttachements() {
    try {
        JobVertex source1 = new JobVertex("source 1");
        JobVertex source2 = new JobVertex("source 2");
        source2.setInvokableClass(DummyInvokable.class);
        JobVertex source3 = new JobVertex("source 3");
        JobVertex intermediate1 = new JobVertex("intermediate 1");
        JobVertex intermediate2 = new JobVertex("intermediate 2");
        JobVertex join1 = new JobVertex("join 1");
        JobVertex join2 = new JobVertex("join 2");
        JobVertex sink1 = new JobVertex("sink 1");
        JobVertex sink2 = new JobVertex("sink 2");
        intermediate1.connectNewDataSetAsInput(source1, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
        intermediate2.connectNewDataSetAsInput(source2, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
        join1.connectNewDataSetAsInput(intermediate1, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);
        join1.connectNewDataSetAsInput(intermediate2, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);
        join2.connectNewDataSetAsInput(join1, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
        join2.connectNewDataSetAsInput(source3, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);
        sink1.connectNewDataSetAsInput(join2, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
        sink2.connectNewDataSetAsInput(join1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
        JobGraph jg = new JobGraph("my job", source1, source2, source3, intermediate1, intermediate2, join1, join2, sink1, sink2);
        String plan = JsonPlanGenerator.generatePlan(jg);
        assertNotNull(plan);
        // validate the produced JSON
        ObjectMapper m = new ObjectMapper();
        JsonNode rootNode = m.readTree(plan);
        // core fields
        assertEquals(new TextNode(jg.getJobID().toString()), rootNode.get("jid"));
        assertEquals(new TextNode(jg.getName()), rootNode.get("name"));
        assertTrue(rootNode.path("nodes").isArray());
        for (Iterator<JsonNode> iter = rootNode.path("nodes").elements(); iter.hasNext(); ) {
            JsonNode next = iter.next();
            JsonNode idNode = next.get("id");
            assertNotNull(idNode);
            assertTrue(idNode.isTextual());
            checkVertexExists(idNode.asText(), jg);
            String description = next.get("description").asText();
            assertTrue(description.startsWith("source") || description.startsWith("sink") || description.startsWith("intermediate") || description.startsWith("join"));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project jsonschema2pojo by joelittlejohn.

the class FormatRuleJodaTest method applyGeneratesTypeFromFormatValue.

@Test
public void applyGeneratesTypeFromFormatValue() {
    TextNode formatNode = TextNode.valueOf(formatValue);
    JType result = rule.apply("fooBar", formatNode, new JCodeModel().ref(String.class), null);
    assertThat(result.fullName(), equalTo(expectedType.getName()));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 3 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project jsonschema2pojo by joelittlejohn.

the class FormatRuleTest method applyDefaultsToBaseType.

@Test
public void applyDefaultsToBaseType() {
    TextNode formatNode = TextNode.valueOf("unknown-format");
    JType baseType = new JCodeModel().ref(Long.class);
    JType result = rule.apply("fooBar", formatNode, baseType, null);
    assertThat(result, equalTo(baseType));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 4 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project swagger-core by swagger-api.

the class PropertyDeserializer method getEnum.

private static List<String> getEnum(JsonNode node, PropertyBuilder.PropertyId type) {
    final List<String> result = new ArrayList<String>();
    JsonNode detailNode = getDetailNode(node, type);
    if (detailNode != null) {
        ArrayNode an = (ArrayNode) detailNode;
        for (JsonNode child : an) {
            if (child instanceof TextNode || child instanceof NumericNode || child instanceof IntNode || child instanceof LongNode || child instanceof DoubleNode || child instanceof FloatNode) {
                result.add(child.asText());
            }
        }
    }
    return result.isEmpty() ? null : result;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayList(java.util.ArrayList) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode)

Example 5 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project Gaffer by gchq.

the class HyperLogLogPlusJsonDeserialiser method deserialize.

// TODO - See 'Can't create HyperLogLogPlus sketches in JSON'
@Override
public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
    final TreeNode coreHyperLogLogPlusObject = treeNode.get("hyperLogLogPlus");
    if (coreHyperLogLogPlusObject != null) {
        final TextNode jsonNodes = (TextNode) coreHyperLogLogPlusObject.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);
        final byte[] nodeAsString = jsonNodes.binaryValue();
        final HyperLogLogPlus hyperLogLogPlus = HyperLogLogPlus.Builder.build(nodeAsString);
        return hyperLogLogPlus;
    } else {
        throw new IllegalArgumentException("Recieved null or empty HyperLogLogPlus sketch");
    }
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)23 Test (org.junit.Test)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 IntNode (com.fasterxml.jackson.databind.node.IntNode)7 ArrayList (java.util.ArrayList)7 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)6 JCodeModel (com.sun.codemodel.JCodeModel)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)4 JType (com.sun.codemodel.JType)4 List (java.util.List)4 TreeNode (com.fasterxml.jackson.core.TreeNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 JDefinedClass (com.sun.codemodel.JDefinedClass)2 JDocComment (com.sun.codemodel.JDocComment)2 NavMap (com.xrtb.blocks.NavMap)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2