Package com.fasterxml.jackson.dataformat.xml.util

## Class DefaultXmlPrettyPrinter

- java.lang.Object
- - com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter

All Implemented Interfaces:
  `com.fasterxml.jackson.core.PrettyPrinter`, `com.fasterxml.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>`, `XmlPrettyPrinter`, `java.io.Serializable`

    public class DefaultXmlPrettyPrinter
    extends java.lang.Object
    implements XmlPrettyPrinter, com.fasterxml.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>, java.io.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:
  Serialized Form

### Nested Class Summary

Nested Classes
`protected static class` `DefaultXmlPrettyPrinter.FixedSpaceIndenter` This is a very simple indenter that only every adds a single space for indentation.
`static interface` `DefaultXmlPrettyPrinter.Indenter` Interface that defines objects that can produce indentation used to separate object entries and array values.
`protected static class` `DefaultXmlPrettyPrinter.Lf2SpacesIndenter` Default linefeed-based indenter uses system-specific linefeeds and 2 spaces for indentation per level.
`protected static class` `DefaultXmlPrettyPrinter.NopIndenter` Dummy implementation that adds no indentation whatsoever

### Field Summary

Fields
`protected DefaultXmlPrettyPrinter.Indenter` `_arrayIndenter` By default, let's use only spaces to separate array values.
`protected boolean` `_justHadStartElement` Marker flag set on start element, and cleared if an end element is encountered.
`protected int` `_nesting` Number of open levels of nesting.
`protected DefaultXmlPrettyPrinter.Indenter` `_objectIndenter` By default, let's use linefeed-adding indenter for separate object entries.
`protected boolean` `_spacesInObjectEntries` By default we will add spaces around colons used to separate object fields and values.

### Fields inherited from interface com.fasterxml.jackson.core.PrettyPrinter

`DEFAULT_ROOT_VALUE_SEPARATOR, DEFAULT_SEPARATORS`

### Constructor Summary

Constructors
`` `DefaultXmlPrettyPrinter()`
`protected` `DefaultXmlPrettyPrinter​(DefaultXmlPrettyPrinter base)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `beforeArrayValues​(com.fasterxml.jackson.core.JsonGenerator gen)`
`void` `beforeObjectEntries​(com.fasterxml.jackson.core.JsonGenerator gen)`
`DefaultXmlPrettyPrinter` `createInstance()`
`void` `indentArraysWith​(DefaultXmlPrettyPrinter.Indenter i)`
`void` `indentObjectsWith​(DefaultXmlPrettyPrinter.Indenter i)`
`void` `spacesInObjectEntries​(boolean b)`
`void` `writeArrayValueSeparator​(com.fasterxml.jackson.core.JsonGenerator gen)`
`void` `writeEndArray​(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfValues)`
`void` `writeEndElement​(org.codehaus.stax2.XMLStreamWriter2 sw, int nrOfEntries)` Method for forcibly writing an end element, without going through Jackson generator (and thus, without updating currently active element stack)
`void` `writeEndObject​(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfEntries)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, boolean value)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, byte[] data, int offset, int len)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, char[] buffer, int offset, int len, boolean isCData)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, double value)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, float value)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, int value)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, long value)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, java.lang.String text, boolean isCData)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, java.math.BigDecimal value)`
`void` `writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, java.math.BigInteger value)`
`void` `writeLeafNullElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName)`
`void` `writeObjectEntrySeparator​(com.fasterxml.jackson.core.JsonGenerator gen)`
`void` `writeObjectFieldValueSeparator​(com.fasterxml.jackson.core.JsonGenerator gen)`
`void` `writePrologLinefeed​(org.codehaus.stax2.XMLStreamWriter2 sw)` 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.
`void` `writeRootValueSeparator​(com.fasterxml.jackson.core.JsonGenerator gen)`
`void` `writeStartArray​(com.fasterxml.jackson.core.JsonGenerator gen)`
`void` `writeStartElement​(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName)` Method for forcibly writing a start element, without going through Jackson generator (and thus, without updating currently active element stack)
`void` `writeStartObject​(com.fasterxml.jackson.core.JsonGenerator gen)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### _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)

#### _spacesInObjectEntries

    protected boolean _spacesInObjectEntries

By default we will add spaces around colons used to separate object fields and values. If disabled, will not use spaces around colon.

#### _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 Detail

#### DefaultXmlPrettyPrinter

    public DefaultXmlPrettyPrinter()

#### DefaultXmlPrettyPrinter

    protected DefaultXmlPrettyPrinter​(DefaultXmlPrettyPrinter base)

### Method Detail

#### indentArraysWith

    public void indentArraysWith​(DefaultXmlPrettyPrinter.Indenter i)

#### indentObjectsWith

    public void indentObjectsWith​(DefaultXmlPrettyPrinter.Indenter i)

#### spacesInObjectEntries

    public void spacesInObjectEntries​(boolean b)

#### createInstance

    public DefaultXmlPrettyPrinter createInstance()

Specified by:
  `createInstance` in interface `com.fasterxml.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>`

#### writeRootValueSeparator

    public void writeRootValueSeparator​(com.fasterxml.jackson.core.JsonGenerator gen)
                                 throws java.io.IOException

Specified by:
  `writeRootValueSeparator` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### beforeArrayValues

    public void beforeArrayValues​(com.fasterxml.jackson.core.JsonGenerator gen)
                           throws java.io.IOException

Specified by:
  `beforeArrayValues` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### writeStartArray

    public void writeStartArray​(com.fasterxml.jackson.core.JsonGenerator gen)
                         throws java.io.IOException

Specified by:
  `writeStartArray` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### writeArrayValueSeparator

    public void writeArrayValueSeparator​(com.fasterxml.jackson.core.JsonGenerator gen)
                                  throws java.io.IOException

Specified by:
  `writeArrayValueSeparator` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### writeEndArray

    public void writeEndArray​(com.fasterxml.jackson.core.JsonGenerator gen,
                              int nrOfValues)
                       throws java.io.IOException

Specified by:
  `writeEndArray` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### beforeObjectEntries

    public void beforeObjectEntries​(com.fasterxml.jackson.core.JsonGenerator gen)
                             throws java.io.IOException,
                                    com.fasterxml.jackson.core.JsonGenerationException

Specified by:
  `beforeObjectEntries` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`
  `com.fasterxml.jackson.core.JsonGenerationException`

#### writeStartObject

    public void writeStartObject​(com.fasterxml.jackson.core.JsonGenerator gen)
                          throws java.io.IOException

Specified by:
  `writeStartObject` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### writeObjectEntrySeparator

    public void writeObjectEntrySeparator​(com.fasterxml.jackson.core.JsonGenerator gen)
                                   throws java.io.IOException

Specified by:
  `writeObjectEntrySeparator` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### writeObjectFieldValueSeparator

    public void writeObjectFieldValueSeparator​(com.fasterxml.jackson.core.JsonGenerator gen)
                                        throws java.io.IOException

Specified by:
  `writeObjectFieldValueSeparator` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### writeEndObject

    public void writeEndObject​(com.fasterxml.jackson.core.JsonGenerator gen,
                               int nrOfEntries)
                        throws java.io.IOException

Specified by:
  `writeEndObject` in interface `com.fasterxml.jackson.core.PrettyPrinter`
Throws:
  `java.io.IOException`

#### writeStartElement

    public void writeStartElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                  java.lang.String nsURI,
                                  java.lang.String localName)
                           throws javax.xml.stream.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:
  `javax.xml.stream.XMLStreamException`

#### writeEndElement

    public void writeEndElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                int nrOfEntries)
                         throws javax.xml.stream.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:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 java.lang.String text,
                                 boolean isCData)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 char[] buffer,
                                 int offset,
                                 int len,
                                 boolean isCData)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 boolean value)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 int value)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 long value)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 double value)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 float value)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 java.math.BigInteger value)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 java.math.BigDecimal value)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafElement

    public void writeLeafElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                 java.lang.String nsURI,
                                 java.lang.String localName,
                                 byte[] data,
                                 int offset,
                                 int len)
                          throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writeLeafNullElement

    public void writeLeafNullElement​(org.codehaus.stax2.XMLStreamWriter2 sw,
                                     java.lang.String nsURI,
                                     java.lang.String localName)
                              throws javax.xml.stream.XMLStreamException

Specified by:
  `writeLeafNullElement` in interface `XmlPrettyPrinter`
Throws:
  `javax.xml.stream.XMLStreamException`

#### writePrologLinefeed

    public void writePrologLinefeed​(org.codehaus.stax2.XMLStreamWriter2 sw)
                             throws javax.xml.stream.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:
  `javax.xml.stream.XMLStreamException`