Jackson Data Binding Source Code

Jackson is "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java".

  • Jackson Data Binding module allows you to converts JSON to and from POJO (Plain Old Java Object) using property accessor or using annotations.
  • Jackson Databind Source Code files are provided in the source packge (jackson-databind-2.12.4-sources.jar). You can download it at Jackson Maven Website.

    You can also browse Jackson Databind Source Code below:

    ✍: FYIcenter.com

    com/fasterxml/jackson/databind/ser/std/NullSerializer.java

    package com.fasterxml.jackson.databind.ser.std;
    
    import java.lang.reflect.Type;
    import java.io.IOException;
    
    import com.fasterxml.jackson.core.*;
    import com.fasterxml.jackson.databind.*;
    import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
    import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
    import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
    
    /**
     * 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).
     */
    @JacksonStdImpl
    @SuppressWarnings("serial")
    public class NullSerializer
        extends StdSerializer<Object>
    {
        public final static NullSerializer instance = new NullSerializer();
        
        private NullSerializer() { super(Object.class); }
        
        @Override
        public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
            gen.writeNull();
        }
    
        /**
         * Although this method should rarely get called, for convenience we should override
         * it, and handle it same way as "natural" types: by serializing exactly as is,
         * without type decorations. The most common possible use case is that of delegation
         * by JSON filter; caller cannot know what kind of serializer it gets handed.
         */
        @Override
        public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider serializers,
                TypeSerializer typeSer)
            throws IOException
        {
            gen.writeNull();
        }
        
        @Override
        public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException {
            return createSchemaNode("null");
        }
        
        @Override
        public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
            visitor.expectNullFormat(typeHint);
        }
    }
    

    com/fasterxml/jackson/databind/ser/std/NullSerializer.java

     

    ⇒ Jackson Annotations Source Code

    ⇐ Download and Install Jackson Binary Package

    ⇑ Downloading and Reviewing jackson-*.jar

    ⇑⇑ Jackson - Java JSON library

    2022-03-29, 31978👍, 0💬