Module tools.jackson.dataformat.xml
Class DefaultXmlPrettyPrinter
java.lang.Object
tools.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter
- All Implemented Interfaces:
Serializable,tools.jackson.core.PrettyPrinter,tools.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>,XmlPrettyPrinter
public class DefaultXmlPrettyPrinter
extends Object
implements XmlPrettyPrinter, tools.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 classThis is a very simple indenter that only every adds a single space for indentation.static interfaceInterface that defines objects that can produce indentation used to separate object entries and array values.protected classDefault linefeed-based indenter uses system-specific linefeeds and 2 spaces for indentation per level.protected static classDummy implementation that adds no indentation whatsoever -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DefaultXmlPrettyPrinter.IndenterBy default, let's use only spaces to separate array values.protected booleanMarker flag set on start element, and cleared if an end element is encountered.protected intNumber of open levels of nesting.protected Stringprotected DefaultXmlPrettyPrinter.IndenterBy default, let's use linefeed-adding indenter for separate object entries.Fields inherited from interface tools.jackson.core.PrettyPrinter
DEFAULT_ROOT_VALUE_SEPARATOR, DEFAULT_SEPARATORS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeArrayValues(tools.jackson.core.JsonGenerator gen) voidbeforeObjectEntries(tools.jackson.core.JsonGenerator gen) voidvoidwithCustomNewLine(String newLine) Sets custom new-line.voidwriteArrayValueSeparator(tools.jackson.core.JsonGenerator gen) voidwriteEndArray(tools.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(tools.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, 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) voidwriteLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName, org.codehaus.stax2.typed.Base64Variant base64variant, byte[] data, int offset, int len) voidwriteLeafNullElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) voidwriteLeafXsiNilElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) voidwriteObjectEntrySeparator(tools.jackson.core.JsonGenerator gen) voidwriteObjectNameValueSeparator(tools.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(tools.jackson.core.JsonGenerator gen) voidwriteStartArray(tools.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(tools.jackson.core.JsonGenerator gen)
-
Field Details
-
_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) -
_newLine
-
_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:
createInstancein interfacetools.jackson.core.util.Instantiatable<DefaultXmlPrettyPrinter>
-
writeRootValueSeparator
public void writeRootValueSeparator(tools.jackson.core.JsonGenerator gen) - Specified by:
writeRootValueSeparatorin interfacetools.jackson.core.PrettyPrinter
-
beforeArrayValues
public void beforeArrayValues(tools.jackson.core.JsonGenerator gen) - Specified by:
beforeArrayValuesin interfacetools.jackson.core.PrettyPrinter
-
writeStartArray
public void writeStartArray(tools.jackson.core.JsonGenerator gen) - Specified by:
writeStartArrayin interfacetools.jackson.core.PrettyPrinter
-
writeArrayValueSeparator
public void writeArrayValueSeparator(tools.jackson.core.JsonGenerator gen) - Specified by:
writeArrayValueSeparatorin interfacetools.jackson.core.PrettyPrinter
-
writeEndArray
public void writeEndArray(tools.jackson.core.JsonGenerator gen, int nrOfValues) - Specified by:
writeEndArrayin interfacetools.jackson.core.PrettyPrinter
-
beforeObjectEntries
public void beforeObjectEntries(tools.jackson.core.JsonGenerator gen) - Specified by:
beforeObjectEntriesin interfacetools.jackson.core.PrettyPrinter
-
writeStartObject
public void writeStartObject(tools.jackson.core.JsonGenerator gen) throws tools.jackson.core.JacksonException - Specified by:
writeStartObjectin interfacetools.jackson.core.PrettyPrinter- Throws:
tools.jackson.core.JacksonException
-
writeObjectEntrySeparator
public void writeObjectEntrySeparator(tools.jackson.core.JsonGenerator gen) throws tools.jackson.core.JacksonException - Specified by:
writeObjectEntrySeparatorin interfacetools.jackson.core.PrettyPrinter- Throws:
tools.jackson.core.JacksonException
-
writeObjectNameValueSeparator
public void writeObjectNameValueSeparator(tools.jackson.core.JsonGenerator gen) throws tools.jackson.core.JacksonException - Specified by:
writeObjectNameValueSeparatorin interfacetools.jackson.core.PrettyPrinter- Throws:
tools.jackson.core.JacksonException
-
writeEndObject
public void writeEndObject(tools.jackson.core.JsonGenerator gen, int nrOfEntries) throws tools.jackson.core.JacksonException - Specified by:
writeEndObjectin interfacetools.jackson.core.PrettyPrinter- Throws:
tools.jackson.core.JacksonException
-
writeStartElement
public void writeStartElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException Description 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 XMLStreamException Description 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, org.codehaus.stax2.typed.Base64Variant base64variant, 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
-
writeLeafXsiNilElement
public void writeLeafXsiNilElement(org.codehaus.stax2.XMLStreamWriter2 sw, String nsURI, String localName) throws XMLStreamException - Specified by:
writeLeafXsiNilElementin interfaceXmlPrettyPrinter- Throws:
XMLStreamException
-
writePrologLinefeed
Description 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
-