Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.ser.std;
 
 
 
This is a simple dummy serializer that will just output literal JSON null value whenever serialization is requested. Used as the default "null serializer" (which is used for serializing null object references unless overridden), as well as for some more exotic types (java.lang.Void).
public class NullSerializer
    extends StdSerializer<Object>
    public final static NullSerializer instance = new NullSerializer();
    
    private NullSerializer() { super(Object.class); }
    
    @Override
    public void serialize(Object valueJsonGenerator jgenSerializerProvider provider)
        throws IOExceptionJsonGenerationException
    {
        jgen.writeNull();
    }
    
    @Override
    public JsonNode getSchema(SerializerProvider providerType typeHint)
        throws JsonMappingException
    {
        return createSchemaNode("null");
    }
    
    @Override
    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitorJavaType typeHint)
    {
    	visitor.expectNullFormat(typeHint);
    }
New to GrepCode? Check out our FAQ X