Class DefaultXmlPrettyPrinter
- java.lang.Object
-
- com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter
-
- All Implemented Interfaces:
PrettyPrinter
,Instantiatable<DefaultXmlPrettyPrinter>
,XmlPrettyPrinter
,java.io.Serializable
public class DefaultXmlPrettyPrinter extends java.lang.Object implements XmlPrettyPrinter, 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 byToXmlGenerator
; because of this, implementation is bit briefer (and uglier...).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DefaultXmlPrettyPrinter.Indenter
Interface that defines objects that can produce indentation used to separate object entries and array values.
-
Field Summary
-
Fields inherited from interface com.fasterxml.jackson.core.PrettyPrinter
DEFAULT_ROOT_VALUE_SEPARATOR, DEFAULT_SEPARATORS
-
-
Constructor Summary
Constructors Constructor Description DefaultXmlPrettyPrinter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beforeArrayValues(JsonGenerator gen)
Method called after array start marker has been output, and right before the first value is to be output.void
beforeObjectEntries(JsonGenerator gen)
Method called after object start marker has been output, and right before the field name of the first entry is to be output.DefaultXmlPrettyPrinter
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.void
indentArraysWith(DefaultXmlPrettyPrinter.Indenter i)
void
indentObjectsWith(DefaultXmlPrettyPrinter.Indenter i)
DefaultXmlPrettyPrinter
withCustomNewLine(java.lang.String newLine)
Sets custom new-line.void
writeArrayValueSeparator(JsonGenerator gen)
Method called after an array value has been completely output, and before another value is to be output.void
writeEndArray(JsonGenerator gen, int nrOfValues)
Method called after an Array value has been completely output (minus closing bracket).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(JsonGenerator gen, int nrOfEntries)
Method called after an Object value has been completely output (minus closing curly bracket).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, 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
writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, org.codehaus.stax2.typed.Base64Variant base64variant, byte[] data, int offset, int len)
void
writeLeafNullElement(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName)
void
writeLeafXsiNilElement(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName)
void
writeObjectEntrySeparator(JsonGenerator gen)
Method called after an Object entry (field:value) has been completely output, and before another value is to be output.void
writeObjectFieldValueSeparator(JsonGenerator gen)
Method called after an object field has been output, but before the value is output.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(JsonGenerator gen)
Method called after a root-level value has been completely output, and before another value is to be output.void
writeStartArray(JsonGenerator gen)
Method called when an Array value is to be output, before any member/child values are output.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(JsonGenerator gen)
Method called when an Object value is to be output, before any fields are output.
-
-
-
Method Detail
-
indentArraysWith
public void indentArraysWith(DefaultXmlPrettyPrinter.Indenter i)
-
indentObjectsWith
public void indentObjectsWith(DefaultXmlPrettyPrinter.Indenter i)
-
withCustomNewLine
public DefaultXmlPrettyPrinter withCustomNewLine(java.lang.String newLine)
Sets custom new-line.- Since:
- 2.15
-
createInstance
public DefaultXmlPrettyPrinter createInstance()
Description copied from interface:Instantiatable
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.- Specified by:
createInstance
in interfaceInstantiatable<DefaultXmlPrettyPrinter>
- Returns:
- Actual instance to use
-
writeRootValueSeparator
public void writeRootValueSeparator(JsonGenerator gen) throws java.io.IOException
Description copied from interface:PrettyPrinter
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).
- Specified by:
writeRootValueSeparator
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
beforeArrayValues
public void beforeArrayValues(JsonGenerator gen) throws java.io.IOException
Description copied from interface:PrettyPrinter
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.
- Specified by:
beforeArrayValues
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
writeStartArray
public void writeStartArray(JsonGenerator gen) throws java.io.IOException
Description copied from interface:PrettyPrinter
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.
- Specified by:
writeStartArray
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
writeArrayValueSeparator
public void writeArrayValueSeparator(JsonGenerator gen) throws java.io.IOException
Description copied from interface:PrettyPrinter
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.
- Specified by:
writeArrayValueSeparator
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
writeEndArray
public void writeEndArray(JsonGenerator gen, int nrOfValues) throws java.io.IOException
Description copied from interface:PrettyPrinter
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.
- Specified by:
writeEndArray
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for outputnrOfValues
- Number of direct members of the array that have been output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
beforeObjectEntries
public void beforeObjectEntries(JsonGenerator gen) throws java.io.IOException, JsonGenerationException
Description copied from interface:PrettyPrinter
Method called after object start marker has been output, and right before the field name of the first entry is to be output. It is not called for objects without entries.Default handling does not output anything, but pretty-printer is free to add any white space decoration.
- Specified by:
beforeObjectEntries
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layerJsonGenerationException
-
writeStartObject
public void writeStartObject(JsonGenerator gen) throws java.io.IOException
Description copied from interface:PrettyPrinter
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.
- Specified by:
writeStartObject
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
writeObjectEntrySeparator
public void writeObjectEntrySeparator(JsonGenerator gen) throws java.io.IOException
Description copied from interface:PrettyPrinter
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.
- Specified by:
writeObjectEntrySeparator
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
writeObjectFieldValueSeparator
public void writeObjectFieldValueSeparator(JsonGenerator gen) throws java.io.IOException
Description copied from interface:PrettyPrinter
Method called after an object field 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.
- Specified by:
writeObjectFieldValueSeparator
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
writeEndObject
public void writeEndObject(JsonGenerator gen, int nrOfEntries) throws java.io.IOException
Description copied from interface:PrettyPrinter
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.
- Specified by:
writeEndObject
in interfacePrettyPrinter
- Parameters:
gen
- Generator used for outputnrOfEntries
- Number of direct members of the Object that have been output- Throws:
java.io.IOException
- if there is either an underlying I/O problem or encoding issue at format layer
-
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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- Throws:
javax.xml.stream.XMLStreamException
-
writeLeafElement
public void writeLeafElement(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName, org.codehaus.stax2.typed.Base64Variant base64variant, byte[] data, int offset, int len) throws javax.xml.stream.XMLStreamException
- Specified by:
writeLeafElement
in interfaceXmlPrettyPrinter
- 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 interfaceXmlPrettyPrinter
- Throws:
javax.xml.stream.XMLStreamException
-
writeLeafXsiNilElement
public void writeLeafXsiNilElement(org.codehaus.stax2.XMLStreamWriter2 sw, java.lang.String nsURI, java.lang.String localName) throws javax.xml.stream.XMLStreamException
- 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 interfaceXmlPrettyPrinter
- Throws:
javax.xml.stream.XMLStreamException
-
-