Top Description Inners Fields Constructors Methods
tools.jackson.dataformat.xml.util

public Class DefaultXmlPrettyPrinter

extends Object
implements XmlPrettyPrinter, Instantiatable<DefaultXmlPrettyPrinter>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, tools.jackson.core.util.Instantiatable, tools.jackson.dataformat.xml.XmlPrettyPrinter, tools.jackson.core.PrettyPrinter
Imports
java.math.BigDecimal, .BigInteger, java.util.Arrays, javax.xml.XMLConstants, javax.xml.stream.XMLStreamException, org.codehaus.stax2.XMLStreamWriter2, tools.jackson.core.*, tools.jackson.core.util.Instantiatable, tools.jackson.dataformat.xml.XmlPrettyPrinter, tools.jackson.dataformat.xml.ser.ToXmlGenerator

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...).

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
DefaultXmlPrettyPrinter.FixedSpaceIndenter

This is a very simple indenter that only every adds a single space for indentation.

public static interface
DefaultXmlPrettyPrinter.Indenter

Interface that defines objects that can produce indentation used to separate object entries and array values.

protected 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

Modifier and TypeField and Description
protected DefaultXmlPrettyPrinter.Indenter
_arrayIndenter

By default, let's use only spaces to separate array values.

protected transient boolean
_justHadStartElement

Marker flag set on start element, and cleared if an end element is encountered.

protected transient int
_nesting

Number of open levels of nesting.

protected String
protected DefaultXmlPrettyPrinter.Indenter
_objectIndenter

By default, let's use linefeed-adding indenter for separate object entries.

private static final long
pack-priv static final int
pack-priv static final char[]
private static final String
SYSTEM_DEFAULT_NEW_LINE

By default, will try to set as System.getProperty("line.separator").

Constructor Summary

AccessConstructor and Description
public
protected

Method Summary

Modifier and TypeMethod and Description
public void
beforeArrayValues(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.beforeArrayValues.

Method called after array start marker has been output, and right before the first value is to be output.

public void
beforeObjectEntries(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.beforeObjectEntries.

Method called after object start marker has been output, and right before the Name of the first property is to be output.

public DefaultXmlPrettyPrinter
createInstance()

Implements tools.jackson.core.util.Instantiatable.createInstance.

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.

public void
public void
public DefaultXmlPrettyPrinter
withCustomNewLine(String newLine)

Sets custom new-line.

public void
writeArrayValueSeparator(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeArrayValueSeparator.

Method called after an array value has been completely output, and before another value is to be output.

public void
writeEndArray(JsonGenerator gen, int nrOfValues)

Implements tools.jackson.core.PrettyPrinter.writeEndArray.

Method called after an Array value has been completely output (minus closing bracket).

public void
writeEndElement(XMLStreamWriter2 sw, int nrOfEntries)

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeEndElement.

Method for forcibly writing an end element, without going through Jackson generator (and thus, without updating currently active element stack)

public void
writeEndObject(JsonGenerator gen, int nrOfEntries)

Implements tools.jackson.core.PrettyPrinter.writeEndObject.

Method called after an Object value has been completely output (minus closing curly bracket).

public void
public void
writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, char[] buffer, int offset, int len, boolean isCData)

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

public void
public void
public void
public void
public void
public void
public void
public void
writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, Base64Variant base64variant, byte[] data, int offset, int len)

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

public void
public void
public void
writeObjectEntrySeparator(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeObjectEntrySeparator.

Method called after an Object entry (field:value) has been completely output, and before another value is to be output.

public void
writeObjectNameValueSeparator(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeObjectNameValueSeparator.

Method called after an Object property name has been output, but before the value is output.

public void
writePrologLinefeed(XMLStreamWriter2 sw)

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writePrologLinefeed.

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.

public void
writeRootValueSeparator(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeRootValueSeparator.

Method called after a root-level value has been completely output, and before another value is to be output.

public void
writeStartArray(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeStartArray.

Method called when an Array value is to be output, before any member/child values are output.

public void
writeStartElement(XMLStreamWriter2 sw, String nsURI, String localName)

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeStartElement.

Method for forcibly writing a start element, without going through Jackson generator (and thus, without updating currently active element stack)

public void
writeStartObject(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeStartObject.

Method called when an Object value is to be output, before any fields are output.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_arrayIndenterback to summary
protected DefaultXmlPrettyPrinter.Indenter _arrayIndenter

By default, let's use only spaces to separate array values.

_justHadStartElementback to summary
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
_nestingback to summary
protected transient int _nesting

Number of open levels of nesting. Used to determine amount of indentation to use.

_newLineback to summary
protected String _newLine
_objectIndenterback to summary
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)

serialVersionUIDback to summary
private static final long serialVersionUID
SPACE_COUNTback to summary
pack-priv static final int SPACE_COUNT
SPACESback to summary
pack-priv static final char[] SPACES
SYSTEM_DEFAULT_NEW_LINEback to summary
private static final String SYSTEM_DEFAULT_NEW_LINE

By default, will try to set as System.getProperty("line.separator"). Can later set custom new line with withCustomNewLine method.

Since
2.15

Constructor Detail

DefaultXmlPrettyPrinterback to summary
public DefaultXmlPrettyPrinter()
DefaultXmlPrettyPrinterback to summary
protected DefaultXmlPrettyPrinter(DefaultXmlPrettyPrinter base)

Method Detail

beforeArrayValuesback to summary
public void beforeArrayValues(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.beforeArrayValues.

Doc from tools.jackson.core.PrettyPrinter.beforeArrayValues.

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.

Annotations
@Override
beforeObjectEntriesback to summary
public void beforeObjectEntries(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.beforeObjectEntries.

Doc from tools.jackson.core.PrettyPrinter.beforeObjectEntries.

Method called after object start marker has been output, and right before the Name of the first property is to be output. It is not called for objects without properties.

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

Annotations
@Override
createInstanceback to summary
public DefaultXmlPrettyPrinter createInstance()

Implements tools.jackson.core.util.Instantiatable.createInstance.

Doc from tools.jackson.core.util.Instantiatable.createInstance.

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.

Annotations
@Override
indentArraysWithback to summary
public void indentArraysWith(DefaultXmlPrettyPrinter.Indenter i)
indentObjectsWithback to summary
public void indentObjectsWith(DefaultXmlPrettyPrinter.Indenter i)
withCustomNewLineback to summary
public DefaultXmlPrettyPrinter withCustomNewLine(String newLine)

Sets custom new-line.

Since
2.15
writeArrayValueSeparatorback to summary
public void writeArrayValueSeparator(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeArrayValueSeparator.

Doc from tools.jackson.core.PrettyPrinter.writeArrayValueSeparator.

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.

Annotations
@Override
writeEndArrayback to summary
public void writeEndArray(JsonGenerator gen, int nrOfValues)

Implements tools.jackson.core.PrettyPrinter.writeEndArray.

Doc from tools.jackson.core.PrettyPrinter.writeEndArray.

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.

Annotations
@Override
writeEndElementback to summary
public void writeEndElement(XMLStreamWriter2 sw, int nrOfEntries) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeEndElement.

Doc from tools.jackson.dataformat.xml.XmlPrettyPrinter.writeEndElement.

Method for forcibly writing an end element, without going through Jackson generator (and thus, without updating currently active element stack)

Annotations
@Override
writeEndObjectback to summary
public void writeEndObject(JsonGenerator gen, int nrOfEntries) throws JacksonException

Implements tools.jackson.core.PrettyPrinter.writeEndObject.

Doc from tools.jackson.core.PrettyPrinter.writeEndObject.

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.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, String text, boolean isCData) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, char[] buffer, int offset, int len, boolean isCData) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, boolean value) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, int value) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, long value) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, double value) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, float value) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, BigInteger value) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, BigDecimal value) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafElementback to summary
public void writeLeafElement(XMLStreamWriter2 sw, String nsURI, String localName, Base64Variant base64variant, byte[] data, int offset, int len) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafElement.

Annotations
@Override
writeLeafNullElementback to summary
public void writeLeafNullElement(XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafNullElement.

Annotations
@Override
writeLeafXsiNilElementback to summary
public void writeLeafXsiNilElement(XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeLeafXsiNilElement.

Annotations
@Override
writeObjectEntrySeparatorback to summary
public void writeObjectEntrySeparator(JsonGenerator gen) throws JacksonException

Implements tools.jackson.core.PrettyPrinter.writeObjectEntrySeparator.

Doc from tools.jackson.core.PrettyPrinter.writeObjectEntrySeparator.

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.

Annotations
@Override
writeObjectNameValueSeparatorback to summary
public void writeObjectNameValueSeparator(JsonGenerator gen) throws JacksonException

Implements tools.jackson.core.PrettyPrinter.writeObjectNameValueSeparator.

Doc from tools.jackson.core.PrettyPrinter.writeObjectNameValueSeparator.

Method called after an Object property name 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.

Annotations
@Override
writePrologLinefeedback to summary
public void writePrologLinefeed(XMLStreamWriter2 sw) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writePrologLinefeed.

Doc from tools.jackson.dataformat.xml.XmlPrettyPrinter.writePrologLinefeed.

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.

Annotations
@Override
writeRootValueSeparatorback to summary
public void writeRootValueSeparator(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeRootValueSeparator.

Doc from tools.jackson.core.PrettyPrinter.writeRootValueSeparator.

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).

Annotations
@Override
writeStartArrayback to summary
public void writeStartArray(JsonGenerator gen)

Implements tools.jackson.core.PrettyPrinter.writeStartArray.

Doc from tools.jackson.core.PrettyPrinter.writeStartArray.

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.

Annotations
@Override
writeStartElementback to summary
public void writeStartElement(XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException

Implements tools.jackson.dataformat.xml.XmlPrettyPrinter.writeStartElement.

Doc from tools.jackson.dataformat.xml.XmlPrettyPrinter.writeStartElement.

Method for forcibly writing a start element, without going through Jackson generator (and thus, without updating currently active element stack)

Annotations
@Override
writeStartObjectback to summary
public void writeStartObject(JsonGenerator gen) throws JacksonException

Implements tools.jackson.core.PrettyPrinter.writeStartObject.

Doc from tools.jackson.core.PrettyPrinter.writeStartObject.

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.

Annotations
@Override
tools.jackson.dataformat.xml.util back to summary

protected Class DefaultXmlPrettyPrinter.FixedSpaceIndenter

extends Object
implements Indenter, Serializable
Class Inheritance
  • java.lang.Object
  • tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.FixedSpaceIndenter
All Implemented Interfaces
java.io.Serializable, tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter

This is a very simple indenter that only every adds a single space for indentation. It is used as the default indenter for array values.

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

FixedSpaceIndenterback to summary
public FixedSpaceIndenter()

Method Detail

isInlineback to summary
public boolean isInline()

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.isInline.

Annotations
@Override
writeIndentationback to summary
public void writeIndentation(XMLStreamWriter2 sw, int level) throws XMLStreamException

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override
writeIndentationback to summary
public void writeIndentation(JsonGenerator g, int level) throws JacksonException

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override
tools.jackson.dataformat.xml.util back to summary

public Interface DefaultXmlPrettyPrinter.Indenter

Known Direct Implementers
tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.NopIndenter, tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.FixedSpaceIndenter, tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Lf2SpacesIndenter

Interface that defines objects that can produce indentation used to separate object entries and array values. Indentation in this context just means insertion of white space, independent of whether linefeeds are output.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

True if indenter is considered inline (does not add linefeeds), false otherwise
isInline
()

public void
public void

Method Detail

isInlineback to summary
public boolean isInline()
Returns:boolean

True if indenter is considered inline (does not add linefeeds), false otherwise

writeIndentationback to summary
public void writeIndentation(JsonGenerator g, int level) throws JacksonException
writeIndentationback to summary
public void writeIndentation(XMLStreamWriter2 sw, int level) throws XMLStreamException
tools.jackson.dataformat.xml.util back to summary

protected Class DefaultXmlPrettyPrinter.Lf2SpacesIndenter

extends Object
implements Indenter, Serializable
Class Inheritance
  • java.lang.Object
  • tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Lf2SpacesIndenter
All Implemented Interfaces
java.io.Serializable, tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter

Default linefeed-based indenter uses system-specific linefeeds and 2 spaces for indentation per level.

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Lf2SpacesIndenterback to summary
public Lf2SpacesIndenter()

Method Detail

isInlineback to summary
public boolean isInline()

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.isInline.

Annotations
@Override
writeIndentationback to summary
public void writeIndentation(XMLStreamWriter2 sw, int level) throws XMLStreamException

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override
writeIndentationback to summary
public void writeIndentation(JsonGenerator g, int level) throws JacksonException

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override
tools.jackson.dataformat.xml.util back to summary

protected Class DefaultXmlPrettyPrinter.NopIndenter

extends Object
implements Indenter, Serializable
Class Inheritance
  • java.lang.Object
  • tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.NopIndenter
All Implemented Interfaces
java.io.Serializable, tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter

Dummy implementation that adds no indentation whatsoever

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

NopIndenterback to summary
public NopIndenter()

Method Detail

isInlineback to summary
public boolean isInline()

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.isInline.

Annotations
@Override
writeIndentationback to summary
public void writeIndentation(JsonGenerator jg, int level)

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override
writeIndentationback to summary
public void writeIndentation(XMLStreamWriter2 sw, int level)

Implements tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override