use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.
the class ObjectReaderTest method testCodecUnsupportedWrites.
public void testCodecUnsupportedWrites() throws Exception {
ObjectReader r = MAPPER.readerFor(String.class);
JsonGenerator g = MAPPER.getFactory().createGenerator(new StringWriter());
ObjectNode n = MAPPER.createObjectNode();
try {
r.writeTree(g, n);
fail("Should not pass");
} catch (UnsupportedOperationException e) {
;
}
try {
r.writeValue(g, "Foo");
fail("Should not pass");
} catch (UnsupportedOperationException e) {
;
}
g.close();
g.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.
the class NodeMergeTest method testObjectNodeUpdateValue.
/*
/********************************************************
/* Test methods
/********************************************************
*/
public void testObjectNodeUpdateValue() throws Exception {
ObjectNode base = MAPPER.createObjectNode();
base.put("first", "foo");
assertSame(base, MAPPER.readerForUpdating(base).readValue(aposToQuotes("{'second':'bar', 'third':5, 'fourth':true}")));
assertEquals(4, base.size());
assertEquals("bar", base.path("second").asText());
assertEquals("foo", base.path("first").asText());
assertEquals(5, base.path("third").asInt());
assertTrue(base.path("fourth").asBoolean());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.
the class NodeMergeTest method testObjectDeepUpdate.
public void testObjectDeepUpdate() throws Exception {
ObjectNode base = MAPPER.createObjectNode();
ObjectNode props = base.putObject("props");
props.put("base", 123);
props.put("value", 456);
ArrayNode a = props.putArray("array");
a.add(true);
base.putNull("misc");
assertSame(base, MAPPER.readerForUpdating(base).readValue(aposToQuotes("{'props':{'value':true, 'extra':25.5, 'array' : [ 3 ]}}")));
assertEquals(2, base.size());
ObjectNode resultProps = (ObjectNode) base.get("props");
assertEquals(4, resultProps.size());
assertEquals(123, resultProps.path("base").asInt());
assertTrue(resultProps.path("value").asBoolean());
assertEquals(25.5, resultProps.path("extra").asDouble());
JsonNode n = resultProps.get("array");
assertEquals(ArrayNode.class, n.getClass());
assertEquals(2, n.size());
assertEquals(3, n.get(1).asInt());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.
the class TestBeanConversions method testNodeConvert.
// [Issue-11]: simple cast, for Tree
public void testNodeConvert() throws Exception {
ObjectNode src = (ObjectNode) MAPPER.readTree("{}");
TreeNode node = src;
ObjectNode result = MAPPER.treeToValue(node, ObjectNode.class);
// should just cast...
assertSame(src, result);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project jackson-databind by FasterXML.
the class NullSerializationTest method testCustomNullForTrees.
// #281
public void testCustomNullForTrees() throws Exception {
ObjectNode root = MAPPER.createObjectNode();
root.putNull("a");
// by default, null is... well, null
assertEquals("{\"a\":null}", MAPPER.writeValueAsString(root));
// but then we can customize it:
DefaultSerializerProvider prov = new MyNullProvider();
prov.setNullValueSerializer(new NullSerializer());
ObjectMapper m = new ObjectMapper();
m.setSerializerProvider(prov);
assertEquals("{\"a\":\"foobar\"}", m.writeValueAsString(root));
}
Aggregations