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/deser/impl/JDKValueInstantiators.java

    package com.fasterxml.jackson.databind.deser.impl;
    
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.LinkedHashMap;
    import java.util.Map;
    
    import com.fasterxml.jackson.core.JsonLocation;
    import com.fasterxml.jackson.databind.DeserializationConfig;
    import com.fasterxml.jackson.databind.DeserializationContext;
    import com.fasterxml.jackson.databind.deser.ValueInstantiator;
    import com.fasterxml.jackson.databind.deser.std.JsonLocationInstantiator;
    
    /**
     * Container for a set of {@link ValueInstantiator}s used for certain critical
     * JDK value types, either as performance optimization for initialization time observed
     * by profiling, or due to difficulty in otherwise finding constructors.
     *
     * @since 2.10
     */
    public abstract class JDKValueInstantiators
    {
        public static ValueInstantiator findStdValueInstantiator(DeserializationConfig config,
                Class<?> raw)
        {
            if (raw == JsonLocation.class) {
                return new JsonLocationInstantiator();
            }
            // [databind#1868]: empty List/Set/Map
            // [databind#2416]: optimize commonly needed default creators
            if (Collection.class.isAssignableFrom(raw)) {
                if (raw == ArrayList.class) {
                    return ArrayListInstantiator.INSTANCE;
                }
                if (Collections.EMPTY_SET.getClass() == raw) {
                    return new ConstantValueInstantiator(Collections.EMPTY_SET);
                }
                if (Collections.EMPTY_LIST.getClass() == raw) {
                    return new ConstantValueInstantiator(Collections.EMPTY_LIST);
                }
            } else if (Map.class.isAssignableFrom(raw)) {
                if (raw == LinkedHashMap.class) {
                    return LinkedHashMapInstantiator.INSTANCE;
                }
                if (raw == HashMap.class) {
                    return HashMapInstantiator.INSTANCE;
                }
                if (Collections.EMPTY_MAP.getClass() == raw) {
                    return new ConstantValueInstantiator(Collections.EMPTY_MAP);
                }
            }
            return null;
        }
    
        private static class ArrayListInstantiator
            extends ValueInstantiator.Base
            implements java.io.Serializable
        {
            private static final long serialVersionUID = 2L;
    
            public final static ArrayListInstantiator INSTANCE = new ArrayListInstantiator();
            public ArrayListInstantiator() {
                super(ArrayList.class);
            }
    
            @Override
            public boolean canInstantiate() { return true; }
    
            @Override
            public boolean canCreateUsingDefault() {  return true; }
    
            @Override
            public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
                return new ArrayList<>();
            }
        }
    
        private static class HashMapInstantiator
            extends ValueInstantiator.Base
            implements java.io.Serializable
        {
            private static final long serialVersionUID = 2L;
    
            public final static HashMapInstantiator INSTANCE = new HashMapInstantiator();
    
            public HashMapInstantiator() {
                super(HashMap.class);
            }
    
            @Override
            public boolean canInstantiate() { return true; }
    
            @Override
            public boolean canCreateUsingDefault() {  return true; }
    
            @Override
            public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
                return new HashMap<>();
            }
        }
    
        private static class LinkedHashMapInstantiator
            extends ValueInstantiator.Base
            implements java.io.Serializable
        {
            private static final long serialVersionUID = 2L;
    
            public final static LinkedHashMapInstantiator INSTANCE = new LinkedHashMapInstantiator();
    
            public LinkedHashMapInstantiator() {
                super(LinkedHashMap.class);
            }
    
            @Override
            public boolean canInstantiate() { return true; }
    
            @Override
            public boolean canCreateUsingDefault() {  return true; }
    
            @Override
            public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
                return new LinkedHashMap<>();
            }
        }
    
        private static class ConstantValueInstantiator
            extends ValueInstantiator.Base
            implements java.io.Serializable
        {
            private static final long serialVersionUID = 2L;
    
            protected final Object _value;
    
            public ConstantValueInstantiator(Object value) {
                super(value.getClass());
                _value = value;
            }
    
            @Override // yes, since default ctor works
            public boolean canInstantiate() { return true; }
    
            @Override
            public boolean canCreateUsingDefault() {  return true; }
    
            @Override
            public Object createUsingDefault(DeserializationContext ctxt) throws IOException {
                return _value;
            }
        }
    
    }
    

    com/fasterxml/jackson/databind/deser/impl/JDKValueInstantiators.java

     

    ⇒ Jackson Annotations Source Code

    ⇐ Download and Install Jackson Binary Package

    ⇑ Downloading and Reviewing jackson-*.jar

    ⇑⇑ Jackson - Java JSON library

    2022-03-29, 31966👍, 0💬