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/ext/DOMSerializer.java

    package com.fasterxml.jackson.databind.ext;
    
    import java.io.IOException;
    import java.io.StringWriter;
    
    import javax.xml.XMLConstants;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    
    import org.w3c.dom.Node;
    
    import com.fasterxml.jackson.core.JsonGenerator;
    import com.fasterxml.jackson.databind.JavaType;
    import com.fasterxml.jackson.databind.JsonMappingException;
    import com.fasterxml.jackson.databind.JsonNode;
    import com.fasterxml.jackson.databind.SerializerProvider;
    import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
    import com.fasterxml.jackson.databind.ser.std.StdSerializer;
    
    @SuppressWarnings("serial")
    public class DOMSerializer extends StdSerializer<Node>
    {
        protected final TransformerFactory transformerFactory;
    
        public DOMSerializer() {
            super(Node.class);
            try {
                transformerFactory = TransformerFactory.newInstance();
                transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
            } catch (Exception e) {
                throw new IllegalStateException("Could not instantiate `TransformerFactory`: "+e.getMessage(), e);
            }
        }
    
        @Override
        public void serialize(Node value, JsonGenerator g, SerializerProvider provider)
            throws IOException
        {
            try {
                Transformer transformer = transformerFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                transformer.setOutputProperty(OutputKeys.INDENT, "no");
                StreamResult result = new StreamResult(new StringWriter());
                transformer.transform(new DOMSource(value), result);
                g.writeString(result.getWriter().toString());
            } catch (TransformerConfigurationException e) {
                throw new IllegalStateException("Could not create XML Transformer for writing DOM `Node` value: "+e.getMessage(), e);
            } catch (TransformerException e) {
                provider.reportMappingProblem(e, "DOM `Node` value serialization failed: %s", e.getMessage());
            }
        }
    
        @Override
        public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint) {
            // Well... it is serialized as String
            return createSchemaNode("string", true);
        }
    
        @Override
        public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
            if (visitor != null) visitor.expectAnyFormat(typeHint);
        }
    }
    

    com/fasterxml/jackson/databind/ext/DOMSerializer.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, 46916👍, 0💬