Object#toString() representations.
You can customize the output using the builder-style methods ToStringBuilder#singleLine() ToStringBuilder#skipNulls() and ToStringBuilder#hideFieldNames().
You can either directly list fields to include via ToStringBuilder#add(String, Object) and ToStringBuilder#add(Object)
or you can let the builder do it automatically using reflection, either including the fields declared in this class or including all superclasses.
The builder will automatically handle cycles in the object tree. It also pretty prints arrays and Iterables.
This class is not thread safe.| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Object | |
| private boolean | |
| private final List | |
| private boolean | |
| private boolean | |
| private boolean | |
| private static ToStringContext | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public | ToStringBuilder(final Object
the object to convert to a String instance)Creates a new ToStringBuilder for the given object. |
| Modifier and Type | Method and Description |
|---|---|
| public ToStringBuilder | |
| public ToStringBuilder | |
| public ToStringBuilder | Returns: thisAdds all fields declared in the object's class and its superclasses to the output. |
| public ToStringBuilder | Returns: thisAdds all fields declared directly in the object's class to the output |
| public ToStringBuilder | |
| private ToStringBuilder | |
| private ToStringBuilder. | |
| private ToStringBuilder | |
| private ToStringBuilder | |
| private List | |
| public ToStringBuilder | |
| private void | |
| private void | |
| public ToStringBuilder | Returns: thisFields are printed on a single line, separated by commas instead of newlines |
| public ToStringBuilder | |
| private String | |
| public String | Returns: the String representation of the processed objectOverrides java. Returns a string representation of the object. |
| public ToStringBuilder | Returns: thisBy default, Iterables, Arrays and multiline Strings are pretty-printed. |
| instance | back to summary |
|---|---|
| private final Object instance | |
| multiLine | back to summary |
|---|---|
| private boolean multiLine | |
| parts | back to summary |
|---|---|
| private final List<ToStringBuilder. | |
| prettyPrint | back to summary |
|---|---|
| private boolean prettyPrint | |
| showFieldNames | back to summary |
|---|---|
| private boolean showFieldNames | |
| skipNulls | back to summary |
|---|---|
| private boolean skipNulls | |
| toStringContext | back to summary |
|---|---|
| private static ToStringContext toStringContext | |
| typeName | back to summary |
|---|---|
| private final String typeName | |
| ToStringBuilder | back to summary |
|---|---|
| public ToStringBuilder(final Object instance) Creates a new ToStringBuilder for the given object. If you don't use reflection, then this instance is only used for obtaining its classes' simple name.
| |
| add | back to summary |
|---|---|
public ToStringBuilder add(final String fieldName, final Object value)
| |
| add | back to summary |
|---|---|
public ToStringBuilder add(final Object value)
| |
| addAllFields | back to summary |
|---|---|
| public ToStringBuilder addAllFields() Adds all fields declared in the object's class and its superclasses to the output.
| |
| addDeclaredFields | back to summary |
|---|---|
| public ToStringBuilder addDeclaredFields() Adds all fields declared directly in the object's class to the output
| |
| addField | back to summary |
|---|---|
public ToStringBuilder addField(final String fieldName)
| |
| addField | back to summary |
|---|---|
private ToStringBuilder addField(final Field field)
| |
| addPart | back to summary |
|---|---|
| private ToStringBuilder. | |
| addPart | back to summary |
|---|---|
| private ToStringBuilder addPart(final Object value) | |
| addPart | back to summary |
|---|---|
| private ToStringBuilder addPart(final String fieldName, final Object value) | |
| getAllDeclaredFields | back to summary |
|---|---|
private List
| |
| hideFieldNames | back to summary |
|---|---|
| public ToStringBuilder hideFieldNames() Field names will not be included in the output. Useful for small classes.
| |
| internalToString | back to summary |
|---|---|
| private void internalToString(final Object object, final ToStringBuilder. | |
| serializeIterable | back to summary |
|---|---|
| private void serializeIterable(final Iterable<?> object, final ToStringBuilder. | |
| singleLine | back to summary |
|---|---|
| public ToStringBuilder singleLine() Fields are printed on a single line, separated by commas instead of newlines
| |
| skipNulls | back to summary |
|---|---|
| public ToStringBuilder skipNulls() Fields with null values will be excluded from the output
| |
| toSimpleReferenceString | back to summary |
|---|---|
| private String toSimpleReferenceString(final Object obj) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| verbatimValues | back to summary |
|---|---|
| public ToStringBuilder verbatimValues() By default, Iterables, Arrays and multiline Strings are pretty-printed. Switching to their normal representation makes the toString method significantly faster.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final StringBuilder | |
| private int | |
| private final String | |
| private final String |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public ToStringBuilder. | |
| public ToStringBuilder. | |
| public ToStringBuilder. | |
| public ToStringBuilder. | |
| public String |
| builder | back to summary |
|---|---|
| private final StringBuilder builder | |
| indentation | back to summary |
|---|---|
| private int indentation | |
| indentationString | back to summary |
|---|---|
| private final String indentationString | |
| newLineString | back to summary |
|---|---|
| private final String newLineString | |
| IndentationAwareStringBuilder | back to summary |
|---|---|
| private IndentationAwareStringBuilder() | |
| append | back to summary |
|---|---|
| public ToStringBuilder. | |
| decreaseIndent | back to summary |
|---|---|
| public ToStringBuilder. | |
| increaseIndent | back to summary |
|---|---|
| public ToStringBuilder. | |
| newLine | back to summary |
|---|---|
| public ToStringBuilder. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| Access | Constructor and Description |
|---|---|
| private |
| fieldName | back to summary |
|---|---|
| private String fieldName | |
| value | back to summary |
|---|---|
| private Object value | |
| Part | back to summary |
|---|---|
| private Part() | |