Class XmlMapper

  • All Implemented Interfaces:
    Versioned, java.io.Serializable

    public class XmlMapper
    extends ObjectMapper
    Customized ObjectMapper that will read and write XML instead of JSON, using XML-backed JsonFactory implementation (XmlFactory).

    Mapper itself overrides some aspects of functionality to try to handle data binding aspects as similar to JAXB as possible.

    Note that most of configuration should be done by pre-constructing JacksonXmlModule explicitly, instead of relying on default settings.

    See Also:
    Serialized Form
    • Constructor Detail

      • XmlMapper

        public XmlMapper()
      • XmlMapper

        public XmlMapper​(javax.xml.stream.XMLInputFactory inputF,
                         javax.xml.stream.XMLOutputFactory outF)
        Since:
        2.4
      • XmlMapper

        public XmlMapper​(javax.xml.stream.XMLInputFactory inputF)
        Since:
        2.4
      • XmlMapper

        public XmlMapper​(XmlFactory xmlFactory)
    • Method Detail

      • copy

        public XmlMapper copy()
        Description copied from class: ObjectMapper
        Method for creating a new ObjectMapper instance that has same initial configuration as this instance. Note that this also requires making a copy of the underlying JsonFactory instance.

        Method is typically used when multiple, differently configured mappers are needed. Although configuration is shared, cached serializers and deserializers are NOT shared, which means that the new instance may be re-configured before use; meaning that it behaves the same way as if an instance was constructed from scratch.

        Overrides:
        copy in class ObjectMapper
      • version

        public Version version()
        Description copied from class: ObjectMapper
        Method that will return version information stored in and read from jar that contains this class.
        Specified by:
        version in interface Versioned
        Overrides:
        version in class ObjectMapper
        Returns:
        Version of the component
      • configure

        public ObjectMapper configure​(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f,
                                      boolean state)
      • configure

        public ObjectMapper configure​(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f,
                                      boolean state)
      • enable

        public ObjectMapper enable​(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)
      • enable

        public ObjectMapper enable​(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)
      • disable

        public ObjectMapper disable​(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)
      • disable

        public ObjectMapper disable​(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)
      • readValue

        public <T> T readValue​(javax.xml.stream.XMLStreamReader r,
                               java.lang.Class<T> valueType)
                        throws java.io.IOException
        Method for reading a single XML value from given XML-specific input source; useful for incremental data-binding, combining traversal using basic Stax XMLStreamReader with data-binding by Jackson.
        Throws:
        java.io.IOException
        Since:
        2.4
      • readValue

        public <T> T readValue​(javax.xml.stream.XMLStreamReader r,
                               TypeReference<T> valueTypeRef)
                        throws java.io.IOException
        Method for reading a single XML value from given XML-specific input source; useful for incremental data-binding, combining traversal using basic Stax XMLStreamReader with data-binding by Jackson.
        Throws:
        java.io.IOException
        Since:
        2.4
      • readValue

        public <T> T readValue​(javax.xml.stream.XMLStreamReader r,
                               JavaType valueType)
                        throws java.io.IOException
        Method for reading a single XML value from given XML-specific input source; useful for incremental data-binding, combining traversal using basic Stax XMLStreamReader with data-binding by Jackson.
        Throws:
        java.io.IOException
        Since:
        2.4
      • writeValue

        public void writeValue​(javax.xml.stream.XMLStreamWriter w0,
                               java.lang.Object value)
                        throws java.io.IOException
        Method for serializing given value using specific XMLStreamReader: useful when building large XML files by binding individual items, one at a time.
        Throws:
        java.io.IOException
        Since:
        2.4