Class DefaultXmlPrettyPrinter

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

public class DefaultXmlPrettyPrinter extends Object implements XmlPrettyPrinter, 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:
  • Constructor Details

    • DefaultXmlPrettyPrinter

      public DefaultXmlPrettyPrinter()
  • 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()
      Description copied from interface: Instantiatable
      Method called to ensure that we have a non-blueprint object to use; it is either this object (if stateless), or a newly created object with separate state.
      Specified by:
      createInstance in interface Instantiatable<DefaultXmlPrettyPrinter>
      Returns:
      Actual instance to use
    • writeRootValueSeparator

      public void writeRootValueSeparator(JsonGenerator gen) throws IOException
      Description copied from interface: PrettyPrinter
      Method called after a root-level value has been completely output, and before another value is to be output.

      Default handling (without pretty-printing) will output a space, to allow values to be parsed correctly. Pretty-printer is to output some other suitable and nice-looking separator (tab(s), space(s), linefeed(s) or any combination thereof).

      Specified by:
      writeRootValueSeparator in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • beforeArrayValues

      public void beforeArrayValues(JsonGenerator gen) throws IOException
      Description copied from interface: PrettyPrinter
      Method called after array start marker has been output, and right before the first value is to be output. It is not called for arrays with no values.

      Default handling does not output anything, but pretty-printer is free to add any white space decoration.

      Specified by:
      beforeArrayValues in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • writeStartArray

      public void writeStartArray(JsonGenerator gen) throws IOException
      Description copied from interface: PrettyPrinter
      Method called when an Array value is to be output, before any member/child values are output.

      Default handling (without pretty-printing) will output the opening bracket. Pretty-printer is to output a bracket as well, but can surround that with other (white-space) decoration.

      Specified by:
      writeStartArray in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • writeArrayValueSeparator

      public void writeArrayValueSeparator(JsonGenerator gen) throws IOException
      Description copied from interface: PrettyPrinter
      Method called after an array value has been completely output, and before another value is to be output.

      Default handling (without pretty-printing) will output a single comma to separate the two. Pretty-printer is to output a comma as well, but can surround that with other (white-space) decoration.

      Specified by:
      writeArrayValueSeparator in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • writeEndArray

      public void writeEndArray(JsonGenerator gen, int nrOfValues) throws IOException
      Description copied from interface: PrettyPrinter
      Method called after an Array value has been completely output (minus closing bracket).

      Default handling (without pretty-printing) will output the closing bracket. Pretty-printer is to output a bracket as well, but can surround that with other (white-space) decoration.

      Specified by:
      writeEndArray in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      nrOfValues - Number of direct members of the array that have been output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • beforeObjectEntries

      public void beforeObjectEntries(JsonGenerator gen) throws IOException, JsonGenerationException
      Description copied from interface: PrettyPrinter
      Method called after object start marker has been output, and right before the field name of the first entry is to be output. It is not called for objects without entries.

      Default handling does not output anything, but pretty-printer is free to add any white space decoration.

      Specified by:
      beforeObjectEntries in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
      JsonGenerationException
    • writeStartObject

      public void writeStartObject(JsonGenerator gen) throws IOException
      Description copied from interface: PrettyPrinter
      Method called when an Object value is to be output, before any fields are output.

      Default handling (without pretty-printing) will output the opening curly bracket. Pretty-printer is to output a curly bracket as well, but can surround that with other (white-space) decoration.

      Specified by:
      writeStartObject in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • writeObjectEntrySeparator

      public void writeObjectEntrySeparator(JsonGenerator gen) throws IOException
      Description copied from interface: PrettyPrinter
      Method called after an Object entry (field:value) has been completely output, and before another value is to be output.

      Default handling (without pretty-printing) will output a single comma to separate the two. Pretty-printer is to output a comma as well, but can surround that with other (white-space) decoration.

      Specified by:
      writeObjectEntrySeparator in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • writeObjectFieldValueSeparator

      public void writeObjectFieldValueSeparator(JsonGenerator gen) throws IOException
      Description copied from interface: PrettyPrinter
      Method called after an object field has been output, but before the value is output.

      Default handling (without pretty-printing) will output a single colon to separate the two. Pretty-printer is to output a colon as well, but can surround that with other (white-space) decoration.

      Specified by:
      writeObjectFieldValueSeparator in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • writeEndObject

      public void writeEndObject(JsonGenerator gen, int nrOfEntries) throws IOException
      Description copied from interface: PrettyPrinter
      Method called after an Object value has been completely output (minus closing curly bracket).

      Default handling (without pretty-printing) will output the closing curly bracket. Pretty-printer is to output a curly bracket as well, but can surround that with other (white-space) decoration.

      Specified by:
      writeEndObject in interface PrettyPrinter
      Parameters:
      gen - Generator used for output
      nrOfEntries - Number of direct members of the Object that have been output
      Throws:
      IOException - if there is either an underlying I/O problem or encoding issue at format layer
    • 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
      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