Class DefaultXmlPrettyPrinter

java.lang.Object
tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter
All Implemented Interfaces:
Serializable, tools.jackson.core.PrettyPrinter, tools.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>, XmlPrettyPrinter

public class DefaultXmlPrettyPrinter extends Object implements XmlPrettyPrinter, tools.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>, Serializable
Indentation to use with XML is different from JSON, because JSON requires use of separator characters and XML just basic whitespace.

Note that only a subset of methods of PrettyPrinter actually get called by ToXmlGenerator; because of this, implementation is bit briefer (and uglier...).

See Also:
  • Field Details

    • _arrayIndenter

      protected DefaultXmlPrettyPrinter.Indenter _arrayIndenter
      By default, let's use only spaces to separate array values.
    • _objectIndenter

      protected DefaultXmlPrettyPrinter.Indenter _objectIndenter
      By default, let's use linefeed-adding indenter for separate object entries. We'll further configure indenter to use system-specific linefeeds, and 2 spaces per level (as opposed to, say, single tabs)
    • _newLine

      protected String _newLine
    • _nesting

      protected transient int _nesting
      Number of open levels of nesting. Used to determine amount of indentation to use.
    • _justHadStartElement

      protected transient boolean _justHadStartElement
      Marker flag set on start element, and cleared if an end element is encountered. Used for suppressing indentation to allow empty elements.
      Since:
      2.3
  • Constructor Details

    • DefaultXmlPrettyPrinter

      public DefaultXmlPrettyPrinter()
    • DefaultXmlPrettyPrinter

      protected DefaultXmlPrettyPrinter(DefaultXmlPrettyPrinter base)
  • Method Details

    • indentArraysWith

      public void indentArraysWith(DefaultXmlPrettyPrinter.Indenter i)
    • indentObjectsWith

      public void indentObjectsWith(DefaultXmlPrettyPrinter.Indenter i)
    • withCustomNewLine

      public DefaultXmlPrettyPrinter withCustomNewLine(String newLine)
      Sets custom new-line.
      Since:
      2.15
    • createInstance

      public DefaultXmlPrettyPrinter createInstance()
      Specified by:
      createInstance in interface tools.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>
    • writeRootValueSeparator

      public void writeRootValueSeparator(tools.jackson.core.JsonGenerator gen)
      Specified by:
      writeRootValueSeparator in interface tools.jackson.core.PrettyPrinter
    • beforeArrayValues

      public void beforeArrayValues(tools.jackson.core.JsonGenerator gen)
      Specified by:
      beforeArrayValues in interface tools.jackson.core.PrettyPrinter
    • writeStartArray

      public void writeStartArray(tools.jackson.core.JsonGenerator gen)
      Specified by:
      writeStartArray in interface tools.jackson.core.PrettyPrinter
    • writeArrayValueSeparator

      public void writeArrayValueSeparator(tools.jackson.core.JsonGenerator gen)
      Specified by:
      writeArrayValueSeparator in interface tools.jackson.core.PrettyPrinter
    • writeEndArray

      public void writeEndArray(tools.jackson.core.JsonGenerator gen, int nrOfValues)
      Specified by:
      writeEndArray in interface tools.jackson.core.PrettyPrinter
    • beforeObjectEntries

      public void beforeObjectEntries(tools.jackson.core.JsonGenerator gen)
      Specified by:
      beforeObjectEntries in interface tools.jackson.core.PrettyPrinter
    • writeStartObject

      public void writeStartObject(tools.jackson.core.JsonGenerator gen) throws tools.jackson.core.JacksonException
      Specified by:
      writeStartObject in interface tools.jackson.core.PrettyPrinter
      Throws:
      tools.jackson.core.JacksonException
    • writeObjectEntrySeparator

      public void writeObjectEntrySeparator(tools.jackson.core.JsonGenerator gen) throws tools.jackson.core.JacksonException
      Specified by:
      writeObjectEntrySeparator in interface tools.jackson.core.PrettyPrinter
      Throws:
      tools.jackson.core.JacksonException
    • writeObjectNameValueSeparator

      public void writeObjectNameValueSeparator(tools.jackson.core.JsonGenerator gen) throws tools.jackson.core.JacksonException
      Specified by:
      writeObjectNameValueSeparator in interface tools.jackson.core.PrettyPrinter
      Throws:
      tools.jackson.core.JacksonException
    • writeEndObject

      public void writeEndObject(tools.jackson.core.JsonGenerator gen, int nrOfEntries) throws tools.jackson.core.JacksonException
      Specified by:
      writeEndObject in interface tools.jackson.core.PrettyPrinter
      Throws:
      tools.jackson.core.JacksonException
    • writeStartElement

      public void writeStartElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException
      Description copied from interface: XmlPrettyPrinter
      Method for forcibly writing a start element, without going through Jackson generator (and thus, without updating currently active element stack)
      Specified by:
      writeStartElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeEndElement

      public void writeEndElement(org.codehaus.stax2.XMLStreamWriter2 sw, int nrOfEntries) throws XMLStreamException
      Description copied from interface: XmlPrettyPrinter
      Method for forcibly writing an end element, without going through Jackson generator (and thus, without updating currently active element stack)
      Specified by:
      writeEndElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, String text, boolean isCData) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, char[] buffer, int offset, int len, boolean isCData) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, boolean value) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, int value) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, long value) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, double value) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, float value) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigInteger value) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigDecimal value) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafElement

      public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, org.codehaus.stax2.typed.Base64Variant base64variant, byte[] data, int offset, int len) throws XMLStreamException
      Specified by:
      writeLeafElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafNullElement

      public void writeLeafNullElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException
      Specified by:
      writeLeafNullElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writeLeafXsiNilElement

      public void writeLeafXsiNilElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException
      Specified by:
      writeLeafXsiNilElement in interface XmlPrettyPrinter
      Throws:
      XMLStreamException
    • writePrologLinefeed

      public void writePrologLinefeed(org.codehaus.stax2.XMLStreamWriter2 sw) throws XMLStreamException
      Description copied from interface: XmlPrettyPrinter
      Method for trying to write a linefeed to separate entities outside of the root element (that is, in prolog or epilog), most often called to separate XML declaration from the root element.
      Specified by:
      writePrologLinefeed in interface XmlPrettyPrinter
      Throws:
      XMLStreamException