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.14.0-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/MethodProperty.java

    package com.fasterxml.jackson.databind.deser.impl;
    
    import java.io.IOException;
    import java.lang.annotation.Annotation;
    import java.lang.reflect.Method;
    
    import com.fasterxml.jackson.core.JsonParser;
    import com.fasterxml.jackson.core.JsonToken;
    import com.fasterxml.jackson.databind.*;
    import com.fasterxml.jackson.databind.deser.NullValueProvider;
    import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
    import com.fasterxml.jackson.databind.introspect.*;
    import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
    import com.fasterxml.jackson.databind.util.Annotations;
    
    /**
     * This concrete sub-class implements property that is set
     * using regular "setter" method.
     */
    public final class MethodProperty
        extends SettableBeanProperty
    {
        private static final long serialVersionUID = 1;
    
        protected final AnnotatedMethod _annotated;
        
        /**
         * Setter method for modifying property value; used for
         * "regular" method-accessible properties.
         */
        protected final transient Method _setter;
    
        /**
         * @since 2.9
         */
        final protected boolean _skipNulls;
        
        public MethodProperty(BeanPropertyDefinition propDef,
                JavaType type, TypeDeserializer typeDeser,
                Annotations contextAnnotations, AnnotatedMethod method)
        {
            super(propDef, type, typeDeser, contextAnnotations);
            _annotated = method;
            _setter = method.getAnnotated();
            _skipNulls = NullsConstantProvider.isSkipper(_nullProvider);
        }
    
        protected MethodProperty(MethodProperty src, JsonDeserializer<?> deser,
                NullValueProvider nva) {
            super(src, deser, nva);
            _annotated = src._annotated;
            _setter = src._setter;
            _skipNulls = NullsConstantProvider.isSkipper(nva);
        }
    
        protected MethodProperty(MethodProperty src, PropertyName newName) {
            super(src, newName);
            _annotated = src._annotated;
            _setter = src._setter;
            _skipNulls = src._skipNulls;
        }
    
        /**
         * Constructor used for JDK Serialization when reading persisted object
         */
        protected MethodProperty(MethodProperty src, Method m) {
            super(src);
            _annotated = src._annotated;
            _setter = m;
            _skipNulls = src._skipNulls;
        }
    
        @Override
        public SettableBeanProperty withName(PropertyName newName) {
            return new MethodProperty(this, newName);
        }
        
        @Override
        public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
            if (_valueDeserializer == deser) {
                return this;
            }
            // 07-May-2019, tatu: As per [databind#2303], must keep VD/NVP in-sync if they were
            NullValueProvider nvp = (_valueDeserializer == _nullProvider) ? deser : _nullProvider;
            return new MethodProperty(this, deser, nvp);
        }
    
        @Override
        public SettableBeanProperty withNullProvider(NullValueProvider nva) {
            return new MethodProperty(this, _valueDeserializer, nva);
        }
    
        @Override
        public void fixAccess(DeserializationConfig config) {
            _annotated.fixAccess(
                    config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
        }
    
        /*
        /**********************************************************
        /* BeanProperty impl
        /**********************************************************
         */
        
        @Override
        public <A extends Annotation> A getAnnotation(Class<A> acls) {
            return (_annotated == null) ? null : _annotated.getAnnotation(acls);
        }
    
        @Override public AnnotatedMember getMember() {  return _annotated; }
    
        /*
        /**********************************************************
        /* Overridden methods
        /**********************************************************
         */
    
        @Override
        public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
                Object instance) throws IOException
        {
            Object value;
            if (p.hasToken(JsonToken.VALUE_NULL)) {
                if (_skipNulls) {
                    return;
                }
                value = _nullProvider.getNullValue(ctxt);
            } else if (_valueTypeDeserializer == null) {
                value = _valueDeserializer.deserialize(p, ctxt);
                // 04-May-2018, tatu: [databind#2023] Coercion from String (mostly) can give null
                if (value == null) {
                    if (_skipNulls) {
                        return;
                    }
                    value = _nullProvider.getNullValue(ctxt);
                }
            } else {
                value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
            }
            try {
                _setter.invoke(instance, value);
            } catch (Exception e) {
                _throwAsIOE(p, e, value);
            }
        }
    
        @Override
        public Object deserializeSetAndReturn(JsonParser p,
        		DeserializationContext ctxt, Object instance) throws IOException
        {
            Object value;
            if (p.hasToken(JsonToken.VALUE_NULL)) {
                if (_skipNulls) {
                    return instance;
                }
                value = _nullProvider.getNullValue(ctxt);
            } else if (_valueTypeDeserializer == null) {
                value = _valueDeserializer.deserialize(p, ctxt);
                // 04-May-2018, tatu: [databind#2023] Coercion from String (mostly) can give null
                if (value == null) {
                    if (_skipNulls) {
                        return instance;
                    }
                    value = _nullProvider.getNullValue(ctxt);
                }
            } else {
                value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
            }
            try {
                Object result = _setter.invoke(instance, value);
                return (result == null) ? instance : result;
            } catch (Exception e) {
                _throwAsIOE(p, e, value);
                return null;
            }
        }
    
        @Override
        public final void set(Object instance, Object value) throws IOException
        {
            try {
                _setter.invoke(instance, value);
            } catch (Exception e) {
                // 15-Sep-2015, tatu: How could we get a ref to JsonParser?
                _throwAsIOE(e, value);
            }
        }
    
        @Override
        public Object setAndReturn(Object instance, Object value) throws IOException
        {
            try {
                Object result = _setter.invoke(instance, value);
                return (result == null) ? instance : result;
            } catch (Exception e) {
                // 15-Sep-2015, tatu: How could we get a ref to JsonParser?
                _throwAsIOE(e, value);
                return null;
            }
        }
    
        /*
        /**********************************************************
        /* JDK serialization handling
        /**********************************************************
         */
    
        Object readResolve() {
            return new MethodProperty(this, _annotated.getAnnotated());
        }
    }
    

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

     

    Or download all of them as a single archive file:

    File name: jackson-databind-2.14.0-sources.jar
    File size: 1187952 bytes
    Release date: 2022-11-05
    Download 
    

     

    Jackson Annotations Source Code

    Download and Install Jackson Binary Package

    Downloading and Reviewing jackson-*.jar

    ⇑⇑ Jackson - Java JSON library

    2022-03-29, 81180👍, 0💬