Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.core.util

public Class DefaultPrettyPrinter

extends Object
implements PrettyPrinter, Instantiatable<DefaultPrettyPrinter>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.fasterxml.jackson.core.util.Instantiatable, com.fasterxml.jackson.core.PrettyPrinter
Annotations
@SuppressWarnings:serial
Imports
java.io.*, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.io.SerializedString

Default PrettyPrinter implementation that uses 2-space indentation with platform-default linefeeds. Usually this class is not instantiated directly, but instead method JsonGenerator#useDefaultPrettyPrinter is used, which will use an instance of this class for operation.

If you override this class, take note of Instantiatable, as subclasses will still create an instance of DefaultPrettyPrinter.

This class is designed for the JSON data format. It works on other formats with same logical model (such as binary CBOR and Smile formats), but may not work as-is for other data formats, most notably XML. It may be necessary to use format-specific PrettyPrinter implementation specific to that format.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
DefaultPrettyPrinter.FixedSpaceIndenter

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

public static interface
DefaultPrettyPrinter.Indenter

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

public static class
DefaultPrettyPrinter.NopIndenter

Dummy implementation that adds no indentation whatsoever

Field Summary

Modifier and TypeField and Description
protected DefaultPrettyPrinter.Indenter
_arrayIndenter

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

protected String
protected transient int
_nesting

Number of open levels of nesting.

protected String
protected String
protected DefaultPrettyPrinter.Indenter
_objectIndenter

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

protected SerializableString
_rootSeparator

String printed between root-level values, if any.

protected Separators
protected boolean
_spacesInObjectEntries

By default we will add spaces around colons used to separate object fields and values.

public static final SerializedString
DEFAULT_ROOT_VALUE_SEPARATOR

Hides com.fasterxml.jackson.core.PrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR.

Constant that specifies default "root-level" separator to use between root values: a single space character.
private static final long

Constructor Summary

AccessConstructor and Description
public
public
DefaultPrettyPrinter(String
String to use as root value separator
rootSeparator
)

Deprecated in 2.16. Use the Separators API instead.
Constructor that specifies separator String to use between root values; if null, no separator is printed.
public
DefaultPrettyPrinter(SerializableString
String to use as root value separator
rootSeparator
)

Deprecated in 2.16. Use the Separators API instead.
Constructor that specifies separator String to use between root values; if null, no separator is printed.
public
DefaultPrettyPrinter(DefaultPrettyPrinter base, SerializableString rootSeparator)

Deprecated in 2.16. Use the Separators API instead.
public
public

Method Summary

Modifier and TypeMethod and Description
protected DefaultPrettyPrinter
_withSpaces(boolean state)

public void
beforeArrayValues(JsonGenerator
Generator used for output
g
)

Implements com.fasterxml.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
Generator used for output
g
)

Implements com.fasterxml.jackson.core.PrettyPrinter.beforeObjectEntries.

Method called after object start marker has been output, and right before the field name of the first entry is to be output.
public DefaultPrettyPrinter
createInstance()

Implements com.fasterxml.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 DefaultPrettyPrinter
public DefaultPrettyPrinter
public DefaultPrettyPrinter

Returns:

This pretty-printer instance (for call chaining)
withoutSpacesInObjectEntries
()

Deprecated in 2.16. Use the Separators API instead.
"Mutant factory" method that will return a pretty printer instance that does not use spaces inside object entries; if 'this' instance already does this, it is returned; if not, a new instance will be constructed and returned.
public DefaultPrettyPrinter
withRootSeparator(SerializableString rootSeparator)

Deprecated in 2.16. Use the Separators API instead.
public DefaultPrettyPrinter

Returns:

This pretty-printer instance (for call chaining)
withRootSeparator
(String
Root-level value separator to use
rootSeparator
)

Deprecated in 2.16. Use the Separators API instead.
public DefaultPrettyPrinter

Returns:

This pretty-printer instance (for call chaining)
withSeparators
(Separators
Separator definitions to use
separators
)

Method for configuring separators for this pretty-printer to use

public DefaultPrettyPrinter

Returns:

This pretty-printer instance (for call chaining)
withSpacesInObjectEntries
()

Deprecated in 2.16. Use the Separators API instead.
"Mutant factory" method that will return a pretty printer instance that does use spaces inside object entries; if 'this' instance already does this, it is returned; if not, a new instance will be constructed and returned.
public void
writeArrayValueSeparator(JsonGenerator
Generator used for output
g
)

Implements com.fasterxml.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
Generator used for output
g
,
int
Number of direct members of the array that have been output
nrOfValues
)

Implements com.fasterxml.jackson.core.PrettyPrinter.writeEndArray.

Method called after an Array value has been completely output (minus closing bracket).
public void
writeEndObject(JsonGenerator
Generator used for output
g
,
int
Number of direct members of the Object that have been output
nrOfEntries
)

Implements com.fasterxml.jackson.core.PrettyPrinter.writeEndObject.

Method called after an Object value has been completely output (minus closing curly bracket).
public void
writeObjectEntrySeparator(JsonGenerator
Generator used for output
g
)

Implements com.fasterxml.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
writeObjectFieldValueSeparator(JsonGenerator
Generator used for output
g
)

Implements com.fasterxml.jackson.core.PrettyPrinter.writeObjectFieldValueSeparator.

Method called after an object field has been output, but before the value is output.
public void
writeRootValueSeparator(JsonGenerator
Generator used for output
g
)

Implements com.fasterxml.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
Generator used for output
g
)

Implements com.fasterxml.jackson.core.PrettyPrinter.writeStartArray.

Method called when an Array value is to be output, before any member/child values are output.
public void
writeStartObject(JsonGenerator
Generator used for output
g
)

Implements com.fasterxml.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 DefaultPrettyPrinter.Indenter _arrayIndenter

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

_arrayValueSeparatorback to summary
protected String _arrayValueSeparator
Since
2.16
_nestingback to summary
protected transient int _nesting

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

_objectEntrySeparatorback to summary
protected String _objectEntrySeparator
Since
2.16
_objectFieldValueSeparatorWithSpacesback to summary
protected String _objectFieldValueSeparatorWithSpaces
Since
2.9
_objectIndenterback to summary
protected DefaultPrettyPrinter.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)

_rootSeparatorback to summary
protected SerializableString _rootSeparator

String printed between root-level values, if any.

_separatorsback to summary
protected Separators _separators
Since
2.9
_spacesInObjectEntriesback to summary
protected boolean _spacesInObjectEntries

Deprecated

in 2.16. Use Separators API instead.

By default we will add spaces around colons used to separate object fields and values. If disabled, will not use spaces around colon.

Annotations
@Deprecated
DEFAULT_ROOT_VALUE_SEPARATORback to summary
public static final SerializedString DEFAULT_ROOT_VALUE_SEPARATOR

Hides com.fasterxml.jackson.core.PrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR.

Deprecated

in 2.16. Use the Separators API instead.

Constant that specifies default "root-level" separator to use between root values: a single space character.

Annotations
@Deprecated
Since
2.1
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

DefaultPrettyPrinterback to summary
public DefaultPrettyPrinter()
DefaultPrettyPrinterback to summary
public DefaultPrettyPrinter(String rootSeparator)

Deprecated

in 2.16. Use the Separators API instead.

Constructor that specifies separator String to use between root values; if null, no separator is printed.

Note

simply constructs a SerializedString out of parameter, calls DefaultPrettyPrinter(SerializableString)

Parameters
rootSeparator:String

String to use as root value separator

Annotations
@Deprecated
DefaultPrettyPrinterback to summary
public DefaultPrettyPrinter(SerializableString rootSeparator)

Deprecated

in 2.16. Use the Separators API instead.

Constructor that specifies separator String to use between root values; if null, no separator is printed.

Parameters
rootSeparator:SerializableString

String to use as root value separator

Annotations
@Deprecated
DefaultPrettyPrinterback to summary
public DefaultPrettyPrinter(DefaultPrettyPrinter base, SerializableString rootSeparator)

Deprecated

in 2.16. Use the Separators API instead.

Annotations
@Deprecated
DefaultPrettyPrinterback to summary
public DefaultPrettyPrinter(Separators separators)
Since
2.16
DefaultPrettyPrinterback to summary
public DefaultPrettyPrinter(DefaultPrettyPrinter base)

Copy constructor

Since
2.16

Method Detail

_withSpacesback to summary
protected DefaultPrettyPrinter _withSpaces(boolean state)
beforeArrayValuesback to summary
public void beforeArrayValues(JsonGenerator g) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.beforeArrayValues.

Doc from com.fasterxml.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.

Parameters
g:JsonGenerator

Generator used for output

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem or encoding issue at format layer
beforeObjectEntriesback to summary
public void beforeObjectEntries(JsonGenerator g) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.beforeObjectEntries.

Doc from com.fasterxml.jackson.core.PrettyPrinter.beforeObjectEntries.

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.

Parameters
g:JsonGenerator

Generator used for output

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem or encoding issue at format layer
createInstanceback to summary
public DefaultPrettyPrinter createInstance()

Implements com.fasterxml.jackson.core.util.Instantiatable.createInstance.

Doc from com.fasterxml.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.

Returns:DefaultPrettyPrinter

Actual instance to use

Annotations
@Override
indentArraysWithback to summary
public void indentArraysWith(DefaultPrettyPrinter.Indenter i)
indentObjectsWithback to summary
public void indentObjectsWith(DefaultPrettyPrinter.Indenter i)
withArrayIndenterback to summary
public DefaultPrettyPrinter withArrayIndenter(DefaultPrettyPrinter.Indenter i)
Since
2.3
withObjectIndenterback to summary
public DefaultPrettyPrinter withObjectIndenter(DefaultPrettyPrinter.Indenter i)
Since
2.3
withoutSpacesInObjectEntriesback to summary
public DefaultPrettyPrinter withoutSpacesInObjectEntries()

Deprecated

in 2.16. Use the Separators API instead.

"Mutant factory" method that will return a pretty printer instance that does not use spaces inside object entries; if 'this' instance already does this, it is returned; if not, a new instance will be constructed and returned.

Returns:DefaultPrettyPrinter

This pretty-printer instance (for call chaining)

Annotations
@Deprecated
Since
2.3
withRootSeparatorback to summary
public DefaultPrettyPrinter withRootSeparator(SerializableString rootSeparator)

Deprecated

in 2.16. Use the Separators API instead.

Annotations
@Deprecated
withRootSeparatorback to summary
public DefaultPrettyPrinter withRootSeparator(String rootSeparator)

Deprecated

in 2.16. Use the Separators API instead.

Parameters
rootSeparator:String

Root-level value separator to use

Returns:DefaultPrettyPrinter

This pretty-printer instance (for call chaining)

Annotations
@Deprecated
Since
2.6
withSeparatorsback to summary
public DefaultPrettyPrinter withSeparators(Separators separators)

Method for configuring separators for this pretty-printer to use

Parameters
separators:Separators

Separator definitions to use

Returns:DefaultPrettyPrinter

This pretty-printer instance (for call chaining)

Since
2.9
withSpacesInObjectEntriesback to summary
public DefaultPrettyPrinter withSpacesInObjectEntries()

Deprecated

in 2.16. Use the Separators API instead.

"Mutant factory" method that will return a pretty printer instance that does use spaces inside object entries; if 'this' instance already does this, it is returned; if not, a new instance will be constructed and returned.

Returns:DefaultPrettyPrinter

This pretty-printer instance (for call chaining)

Annotations
@Deprecated
Since
2.3
writeArrayValueSeparatorback to summary
public void writeArrayValueSeparator(JsonGenerator g) throws IOException

Implements com.fasterxml.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.

Parameters
g:JsonGenerator

Doc from com.fasterxml.jackson.core.PrettyPrinter.writeArrayValueSeparator.

Generator used for output

Annotations
@Override
Exceptions
IOException:

Doc from com.fasterxml.jackson.core.PrettyPrinter.writeArrayValueSeparator.

if there is either an underlying I/O problem or encoding issue at format layer

writeEndArrayback to summary
public void writeEndArray(JsonGenerator g, int nrOfValues) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.writeEndArray.

Doc from com.fasterxml.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.

Parameters
g:JsonGenerator

Generator used for output

nrOfValues:int

Number of direct members of the array that have been output

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem or encoding issue at format layer
writeEndObjectback to summary
public void writeEndObject(JsonGenerator g, int nrOfEntries) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.writeEndObject.

Doc from com.fasterxml.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.

Parameters
g:JsonGenerator

Generator used for output

nrOfEntries:int

Number of direct members of the Object that have been output

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem or encoding issue at format layer
writeObjectEntrySeparatorback to summary
public void writeObjectEntrySeparator(JsonGenerator g) throws IOException

Implements com.fasterxml.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.

Parameters
g:JsonGenerator

Doc from com.fasterxml.jackson.core.PrettyPrinter.writeObjectEntrySeparator.

Generator used for output

Annotations
@Override
Exceptions
IOException:

Doc from com.fasterxml.jackson.core.PrettyPrinter.writeObjectEntrySeparator.

if there is either an underlying I/O problem or encoding issue at format layer

writeObjectFieldValueSeparatorback to summary
public void writeObjectFieldValueSeparator(JsonGenerator g) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.writeObjectFieldValueSeparator.

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.

Parameters
g:JsonGenerator

Doc from com.fasterxml.jackson.core.PrettyPrinter.writeObjectFieldValueSeparator.

Generator used for output

Annotations
@Override
Exceptions
IOException:

Doc from com.fasterxml.jackson.core.PrettyPrinter.writeObjectFieldValueSeparator.

if there is either an underlying I/O problem or encoding issue at format layer

writeRootValueSeparatorback to summary
public void writeRootValueSeparator(JsonGenerator g) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.writeRootValueSeparator.

Doc from com.fasterxml.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).

Parameters
g:JsonGenerator

Generator used for output

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem or encoding issue at format layer
writeStartArrayback to summary
public void writeStartArray(JsonGenerator g) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.writeStartArray.

Doc from com.fasterxml.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.

Parameters
g:JsonGenerator

Generator used for output

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem or encoding issue at format layer
writeStartObjectback to summary
public void writeStartObject(JsonGenerator g) throws IOException

Implements com.fasterxml.jackson.core.PrettyPrinter.writeStartObject.

Doc from com.fasterxml.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.

Parameters
g:JsonGenerator

Generator used for output

Annotations
@Override
Exceptions
IOException:
if there is either an underlying I/O problem or encoding issue at format layer
com.fasterxml.jackson.core.util back to summary

public Class DefaultPrettyPrinter.FixedSpaceIndenter

extends NopIndenter
Class Inheritance

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

Field Summary

Modifier and TypeField and Description
public static final DefaultPrettyPrinter.FixedSpaceIndenter

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public void

Field Detail

instanceback to summary
public static final DefaultPrettyPrinter.FixedSpaceIndenter instance

Hides com.fasterxml.jackson.core.util.DefaultPrettyPrinter.NopIndenter.instance.

Constructor Detail

FixedSpaceIndenterback to summary
public FixedSpaceIndenter()

Method Detail

isInlineback to summary
public boolean isInline()

Overrides com.fasterxml.jackson.core.util.DefaultPrettyPrinter.NopIndenter.isInline.

Implements com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter.isInline.

Returns:boolean

Doc from com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter.isInline.

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

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

Overrides com.fasterxml.jackson.core.util.DefaultPrettyPrinter.NopIndenter.writeIndentation.

Implements com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override
com.fasterxml.jackson.core.util back to summary

public Interface DefaultPrettyPrinter.Indenter

Known Direct Implementers
com.fasterxml.jackson.core.util.DefaultPrettyPrinter.NopIndenter

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

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 IOException
com.fasterxml.jackson.core.util back to summary

public Class DefaultPrettyPrinter.NopIndenter

extends Object
implements Indenter, Serializable
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.core.util.DefaultPrettyPrinter.NopIndenter
All Implemented Interfaces
java.io.Serializable, com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter
Known Direct Subclasses
com.fasterxml.jackson.core.util.DefaultPrettyPrinter.FixedSpaceIndenter, com.fasterxml.jackson.core.util.DefaultIndenter

Dummy implementation that adds no indentation whatsoever

Field Summary

Modifier and TypeField and Description
public static final DefaultPrettyPrinter.NopIndenter

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Field Detail

instanceback to summary
public static final DefaultPrettyPrinter.NopIndenter instance

Constructor Detail

NopIndenterback to summary
public NopIndenter()

Method Detail

isInlineback to summary
public boolean isInline()

Implements com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter.isInline.

Returns:boolean

Doc from com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter.isInline.

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

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

Implements com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter.writeIndentation.

Annotations
@Override