Search in sources :

Example 1 with DefaultSerializerProvider

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));
}
Also used : DefaultSerializerProvider(com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)

Example 2 with DefaultSerializerProvider

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultSerializerProvider(com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)

Aggregations

DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1