Search in sources :

Example 1 with TextNode

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

the class ArrayNodeTest method testDirectCreation.

public void testDirectCreation() throws IOException {
    ArrayNode n = new ArrayNode(JsonNodeFactory.instance);
    assertStandardEquals(n);
    assertFalse(n.elements().hasNext());
    assertFalse(n.fieldNames().hasNext());
    TextNode text = TextNode.valueOf("x");
    n.add(text);
    assertEquals(1, n.size());
    assertFalse(0 == n.hashCode());
    assertTrue(n.elements().hasNext());
    // no field names for arrays
    assertFalse(n.fieldNames().hasNext());
    // not used with arrays
    assertNull(n.get("x"));
    assertTrue(n.path("x").isMissingNode());
    assertSame(text, n.get(0));
    // single element, so:
    assertFalse(n.has("field"));
    assertFalse(n.hasNonNull("field"));
    assertTrue(n.has(0));
    assertTrue(n.hasNonNull(0));
    assertFalse(n.has(1));
    assertFalse(n.hasNonNull(1));
    // add null node too
    n.add((JsonNode) null);
    assertEquals(2, n.size());
    assertTrue(n.get(1).isNull());
    assertTrue(n.has(1));
    assertFalse(n.hasNonNull(1));
    // change to text
    n.set(1, text);
    assertSame(text, n.get(1));
    n.set(0, null);
    assertTrue(n.get(0).isNull());
    // and finally, clear it all
    ArrayNode n2 = new ArrayNode(JsonNodeFactory.instance);
    n2.add("foobar");
    assertFalse(n.equals(n2));
    n.addAll(n2);
    assertEquals(3, n.size());
    assertFalse(n.get(0).isTextual());
    assertNotNull(n.remove(0));
    assertEquals(2, n.size());
    assertTrue(n.get(0).isTextual());
    assertNull(n.remove(-1));
    assertNull(n.remove(100));
    assertEquals(2, n.size());
    ArrayList<JsonNode> nodes = new ArrayList<JsonNode>();
    nodes.add(text);
    n.addAll(nodes);
    assertEquals(3, n.size());
    assertNull(n.get(10000));
    assertNull(n.remove(-4));
    TextNode text2 = TextNode.valueOf("b");
    n.insert(0, text2);
    assertEquals(4, n.size());
    assertSame(text2, n.get(0));
    assertNotNull(n.addArray());
    assertEquals(5, n.size());
    n.addPOJO("foo");
    assertEquals(6, n.size());
    // Try serializing it for fun, too...
    JsonGenerator g = objectMapper().getFactory().createGenerator(new StringWriter());
    n.serialize(g, null);
    g.close();
    n.removeAll();
    assertEquals(0, n.size());
}
Also used : ArrayList(java.util.ArrayList) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with TextNode

use of org.apache.flink.shaded.jackson2.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 3 with TextNode

use of org.apache.flink.shaded.jackson2.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)

Example 4 with TextNode

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

the class AbstractServiceTest method createNode.

protected JsonNode createNode(ComponentScope scope, ComponentType type, String clazz, String configurationDescriptor, String configuration) throws IOException {
    getOrCreateDescriptor(scope, type, clazz, configurationDescriptor);
    ObjectNode oNode = mapper.createObjectNode();
    oNode.set("name", new TextNode("test action"));
    oNode.set("clazz", new TextNode(clazz));
    oNode.set("configuration", readFromResource(configuration));
    return oNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 5 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project autorest-clientruntime-for-java by Azure.

the class ValidatorTests method validateRecursive.

@Test
public void validateRecursive() throws Exception {
    TextNode textNode = new TextNode("\"\"");
    Validator.validate(textNode);
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) Test(org.junit.Test)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)96 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)35 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)14 IntNode (com.fasterxml.jackson.databind.node.IntNode)14 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 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 ArrayList (java.util.ArrayList)9 Scheduler (org.apache.kafka.common.utils.Scheduler)9 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)9 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)9 TaskRunning (org.apache.kafka.trogdor.rest.TaskRunning)9 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)8