use of com.fasterxml.jackson.databind.ser.DefaultSerializerProvider in project jackson-databind by FasterXML.
the class NullSerializationTest method testOverriddenDefaultNulls.
public void testOverriddenDefaultNulls() throws Exception {
DefaultSerializerProvider sp = new DefaultSerializerProvider.Impl();
sp.setNullValueSerializer(new NullSerializer());
ObjectMapper m = new ObjectMapper();
m.setSerializerProvider(sp);
assertEquals("\"foobar\"", m.writeValueAsString(null));
}
use of com.fasterxml.jackson.databind.ser.DefaultSerializerProvider 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