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 PrettyPrinter
actually
get called by ToXmlGenerator
; because of this, implementation
is bit briefer (and uglier...).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
This is a very simple indenter that only every adds a single space for indentation.static interface
Interface that defines objects that can produce indentation used to separate object entries and array values.protected class
Default linefeed-based indenter uses system-specific linefeeds and 2 spaces for indentation per level.protected static class
Dummy implementation that adds no indentation whatsoever -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DefaultXmlPrettyPrinter.Indenter
By default, let's use only spaces to separate array values.protected boolean
Marker flag set on start element, and cleared if an end element is encountered.protected int
Number of open levels of nesting.protected String
protected DefaultXmlPrettyPrinter.Indenter
By default, let's use linefeed-adding indenter for separate object entries.private static final long
(package private) static final int
(package private) static final char[]
private static final String
By default, will try to set as System.getProperty("line.separator").Fields inherited from interface com.fasterxml.jackson.core.PrettyPrinter
DEFAULT_ROOT_VALUE_SEPARATOR, DEFAULT_SEPARATORS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
-
Method Summary
Modifier and TypeMethodDescriptionvoid
beforeArrayValues
(com.fasterxml.jackson.core.JsonGenerator gen) void
beforeObjectEntries
(com.fasterxml.jackson.core.JsonGenerator gen) void
void
withCustomNewLine
(String newLine) Sets custom new-line.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, String nsURI, String localName, boolean value) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, char[] buffer, int offset, int len, boolean isCData) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, double value) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, float value) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, int value) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, long value) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, String text, boolean isCData) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigDecimal value) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigInteger value) void
writeLeafElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, org.codehaus.stax2.typed.Base64Variant base64variant, byte[] data, int offset, int len) void
writeLeafNullElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) void
writeLeafXsiNilElement
(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, 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, String nsURI, 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)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
_arrayIndenter
By default, let's use only spaces to separate array values. -
_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) -
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
-
_newLine
-
SPACE_COUNT
static final int SPACE_COUNT- See Also:
-
SPACES
static final char[] SPACES -
_nesting
protected transient int _nestingNumber of open levels of nesting. Used to determine amount of indentation to use. -
_justHadStartElement
protected transient boolean _justHadStartElementMarker 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
-
-
Method Details
-
indentArraysWith
-
indentObjectsWith
-
withCustomNewLine
Sets custom new-line.- Since:
- 2.15
-
createInstance
- Specified by:
createInstance
in interfacecom.fasterxml.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>
-
writeRootValueSeparator
public void writeRootValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException - Specified by:
writeRootValueSeparator
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
beforeArrayValues
- Specified by:
beforeArrayValues
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
writeStartArray
- Specified by:
writeStartArray
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
writeArrayValueSeparator
public void writeArrayValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException - Specified by:
writeArrayValueSeparator
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
writeEndArray
public void writeEndArray(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfValues) throws IOException - Specified by:
writeEndArray
in 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:
beforeObjectEntries
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
com.fasterxml.jackson.core.JsonGenerationException
-
writeStartObject
- Specified by:
writeStartObject
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
writeObjectEntrySeparator
public void writeObjectEntrySeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException - Specified by:
writeObjectEntrySeparator
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
writeObjectFieldValueSeparator
public void writeObjectFieldValueSeparator(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException - Specified by:
writeObjectFieldValueSeparator
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
writeEndObject
public void writeEndObject(com.fasterxml.jackson.core.JsonGenerator gen, int nrOfEntries) throws IOException - Specified by:
writeEndObject
in interfacecom.fasterxml.jackson.core.PrettyPrinter
- Throws:
IOException
-
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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 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:
writeLeafElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, boolean value) throws XMLStreamException - Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, int value) throws XMLStreamException - Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, long value) throws XMLStreamException - Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, double value) throws XMLStreamException - Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, float value) throws XMLStreamException - Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigInteger value) throws XMLStreamException - Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, BigDecimal value) throws XMLStreamException - Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafNullElement
public void writeLeafNullElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException - Specified by:
writeLeafNullElement
in interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-
writeLeafXsiNilElement
public void writeLeafXsiNilElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException - Throws:
XMLStreamException
-
writePrologLinefeed
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 interfaceXmlPrettyPrinter
- Throws:
XMLStreamException
-