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/node/LongNode.java

    package com.fasterxml.jackson.databind.node;
    
    import java.io.IOException;
    import java.math.BigDecimal;
    import java.math.BigInteger;
    
    import com.fasterxml.jackson.core.*;
    import com.fasterxml.jackson.core.io.NumberOutput;
    import com.fasterxml.jackson.databind.SerializerProvider;
    
    
    /**
     * Numeric node that contains simple 64-bit integer values.
     */
    @SuppressWarnings("serial")
    public class LongNode
        extends NumericNode
    {
        protected final long _value;
    
        /* 
        ************************************************
        * Construction
        ************************************************
        */
    
        public LongNode(long v) { _value = v; }
    
        public static LongNode valueOf(long l) { return new LongNode(l); }
    
        /* 
        ************************************************
        * Overrridden JsonNode methods
        ************************************************
        */
    
        @Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
    
        @Override
        public JsonParser.NumberType numberType() { return JsonParser.NumberType.LONG; }
    
    
        @Override
        public boolean isIntegralNumber() { return true; }
    
        @Override
        public boolean isLong() { return true; }
    
        @Override public boolean canConvertToInt() {
            return (_value >= Integer.MIN_VALUE && _value <= Integer.MAX_VALUE);
        }
        @Override public boolean canConvertToLong() { return true; }
        
        @Override
        public Number numberValue() {
            return Long.valueOf(_value);
        }
    
        @Override
        public short shortValue() { return (short) _value; }
    
        @Override
        public int intValue() { return (int) _value; }
    
        @Override
        public long longValue() { return _value; }
    
        @Override
        public float floatValue() { return _value; }
    
        @Override
        public double doubleValue() { return _value; }
    
        @Override
        public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
    
        @Override
        public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
    
        @Override
        public String asText() {
            return NumberOutput.toString(_value);
        }
    
        @Override
        public boolean asBoolean(boolean defaultValue) {
            return _value != 0;
        }
        
        @Override
        public final void serialize(JsonGenerator jg, SerializerProvider provider)
            throws IOException, JsonProcessingException
        {
            jg.writeNumber(_value);
        }
    
        @Override
        public boolean equals(Object o)
        {
            if (o == this) return true;
            if (o == null) return false;
            if (o instanceof LongNode) {
                return ((LongNode) o)._value == _value;
            }
            return false;
        }
    
        @Override
        public int hashCode() {
            return ((int) _value) ^ (int) (_value >> 32);
        }
    }
    

    com/fasterxml/jackson/databind/node/LongNode.java

     

    ⇒ Jackson Annotations Source Code

    ⇐ Download and Install Jackson Binary Package

    ⇑ Downloading and Reviewing jackson-*.jar

    ⇑⇑ Jackson - Java JSON library

    2022-03-29, 31964👍, 0💬