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/NodeSerialization.java

    package com.fasterxml.jackson.databind.node;
    
    import java.io.IOException;
    import java.io.ObjectInput;
    import java.io.ObjectOutput;
    
    /**
     * Helper value class only used during JDK serialization: contains JSON as `byte[]`
     *
     * @since 2.10
     */
    class NodeSerialization implements java.io.Serializable,
        java.io.Externalizable
    {
        private static final long serialVersionUID = 1L;
    
        public byte[] json;
    
        public NodeSerialization() { }
    
        public NodeSerialization(byte[] b) { json = b; }
    
        protected Object readResolve() {
            try {
                return InternalNodeMapper.bytesToNode(json);
            } catch (IOException e) {
                throw new IllegalArgumentException("Failed to JDK deserialize `JsonNode` value: "+e.getMessage(), e);
            }
        }    
    
        public static NodeSerialization from(Object o) {
            try {
                return new NodeSerialization(InternalNodeMapper.valueToBytes(o));
            } catch (IOException e) {
                throw new IllegalArgumentException("Failed to JDK serialize `"+o.getClass().getSimpleName()+"` value: "+e.getMessage(), e);
            }
        }
    
        @Override
        public void writeExternal(ObjectOutput out) throws IOException {
            out.writeInt(json.length);
            out.write(json);
        }
    
        @Override
        public void readExternal(ObjectInput in) throws IOException {
            final int len = in.readInt();
            json = new byte[len];
            in.readFully(json, 0, len);
        }
    }
    

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

     

    ⇒ Jackson Annotations Source Code

    ⇐ Download and Install Jackson Binary Package

    ⇑ Downloading and Reviewing jackson-*.jar

    ⇑⇑ Jackson - Java JSON library

    2022-03-29, 32307👍, 0💬