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