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,Serializable
public class DefaultXmlPrettyPrinter extends Object implements XmlPrettyPrinter, com.fasterxml.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
PrettyPrinteractually get called byToXmlGenerator; because of this, implementation is bit briefer (and uglier...).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDefaultXmlPrettyPrinter.FixedSpaceIndenterThis is a very simple indenter that only every adds a single space for indentation.static interfaceDefaultXmlPrettyPrinter.IndenterInterface that defines objects that can produce indentation used to separate object entries and array values.protected static classDefaultXmlPrettyPrinter.Lf2SpacesIndenterDefault linefeed-based indenter uses system-specific linefeeds and 2 spaces for indentation per level.protected static classDefaultXmlPrettyPrinter.NopIndenterDummy implementation that adds no indentation whatsoever
-
Field Summary
Fields Modifier and Type Field Description protected DefaultXmlPrettyPrinter.Indenter_arrayIndenterBy default, let's use only spaces to separate array values.protected boolean_justHadStartElementMarker flag set on start element, and cleared if an end element is encountered.protected int_nestingNumber of open levels of nesting.protected DefaultXmlPrettyPrinter.Indenter_objectIndenterBy default, let's use linefeed-adding indenter for separate object entries.protected boolean_spacesInObjectEntriesBy default we will add spaces around colons used to separate object fields and values.
-
Constructor Summary
Constructors Modifier Constructor Description DefaultXmlPrettyPrinter()protectedDefaultXmlPrettyPrinter(DefaultXmlPrettyPrinter base)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeforeArrayValues(com.fasterxml.jackson.core.JsonGenerator gen)voidbeforeObjectEntries(com.fasterxml.jackson.core.JsonGenerator gen)DefaultXmlPrettyPrintercreateInstance()voidindentArraysWith(DefaultXmlPrettyPrinter.Indenter i)voidindentObjectsWith(DefaultXmlPrettyPrinter.Indenter i)voidspacesInObjectEntries(boolean b)voidwriteArrayValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen)voidwriteEndArray(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfValues)voidwriteEndElement(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)voidwriteEndObject(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfEntries)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, boolean value)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, byte[] data, int offset, int len)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, char[] buffer, int offset, int len, boolean isCData)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, double value)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, float value)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, int value)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, long value)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, String text, boolean isCData)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigDecimal value)voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigInteger value)voidwriteLeafNullElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName)voidwriteObjectEntrySeparator(com.fasterxml.jackson.core.JsonGenerator gen)voidwriteObjectFieldValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen)voidwritePrologLinefeed(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.voidwriteRootValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen)voidwriteStartArray(com.fasterxml.jackson.core.JsonGenerator gen)voidwriteStartElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName)Method for forcibly writing a start element, without going through Jackson generator (and thus, without updating currently active element stack)voidwriteStartObject(com.fasterxml.jackson.core.JsonGenerator gen)
-
-
-
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:
createInstancein interfacecom.fasterxml.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>
-
writeRootValueSeparator
public void writeRootValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException- Specified by:
writeRootValueSeparatorin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
beforeArrayValues
public void beforeArrayValues(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException- Specified by:
beforeArrayValuesin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
writeStartArray
public void writeStartArray(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException- Specified by:
writeStartArrayin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
writeArrayValueSeparator
public void writeArrayValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException- Specified by:
writeArrayValueSeparatorin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
writeEndArray
public void writeEndArray(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfValues) throws IOException- Specified by:
writeEndArrayin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
beforeObjectEntries
public void beforeObjectEntries(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException, com.fasterxml.jackson.core.JsonGenerationException- Specified by:
beforeObjectEntriesin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOExceptioncom.fasterxml.jackson.core.JsonGenerationException
-
writeStartObject
public void writeStartObject(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException- Specified by:
writeStartObjectin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
writeObjectEntrySeparator
public void writeObjectEntrySeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException- Specified by:
writeObjectEntrySeparatorin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
writeObjectFieldValueSeparator
public void writeObjectFieldValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException- Specified by:
writeObjectFieldValueSeparatorin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
writeEndObject
public void writeEndObject(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfEntries) throws IOException- Specified by:
writeEndObjectin interfacecom.fasterxml.jackson.core.PrettyPrinter- Throws:
IOException
-
writeStartElement
public void writeStartElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamExceptionDescription copied from interface:XmlPrettyPrinterMethod for forcibly writing a start element, without going through Jackson generator (and thus, without updating currently active element stack)- Specified by:
writeStartElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeEndElement
public void writeEndElement(org.codehaus.stax2.XMLStreamWriter2 sw, int nrOfEntries) throws XMLStreamExceptionDescription copied from interface:XmlPrettyPrinterMethod for forcibly writing an end element, without going through Jackson generator (and thus, without updating currently active element stack)- Specified by:
writeEndElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, String text, boolean isCData) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- 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:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, boolean value) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, int value) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, long value) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, double value) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, float value) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigInteger value) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigDecimal value) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, byte[] data, int offset, int len) throws XMLStreamException- Specified by:
writeLeafElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writeLeafNullElement
public void writeLeafNullElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException- Specified by:
writeLeafNullElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writePrologLinefeed
public void writePrologLinefeed(org.codehaus.stax2.XMLStreamWriter2 sw) throws XMLStreamExceptionDescription copied from interface:XmlPrettyPrinterMethod 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:
writePrologLinefeedin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
-