public class RecursiveToStringStyle extends ToStringStyle
Works with ToStringBuilder
to create a "deep" toString
.
To use this class write code as follows:
public class Job { String title; ... } public class Person { String name; int age; boolean smoker; Job job; ... public String toString() { return new ReflectionToStringBuilder(this, new RecursiveToStringStyle()).toString(); } }
This will produce a toString of the format:
Person@7f54[name=Stephen,age=29,smoker=false,job=Job@43cd2[title=Manager]]
DEFAULT_STYLE, JSON_STYLE, MULTI_LINE_STYLE, NO_CLASS_NAME_STYLE, NO_FIELD_NAMES_STYLE, SHORT_PREFIX_STYLE, SIMPLE_STYLE
Constructor and Description |
---|
RecursiveToStringStyle()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
accept(Class<?> clazz)
Returns whether or not to recursively format the given
Class . |
protected void |
appendDetail(StringBuffer buffer,
String fieldName,
Collection<?> coll)
Append to the
toString a Collection . |
void |
appendDetail(StringBuffer buffer,
String fieldName,
Object value)
Append to the
toString an Object
value, printing the full detail of the Object . |
append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, appendClassName, appendContentEnd, appendContentStart, appendCyclicObject, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendEnd, appendFieldEnd, appendFieldSeparator, appendFieldStart, appendIdentityHashCode, appendInternal, appendNullText, appendStart, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummarySize, appendSuper, appendToString, getArrayEnd, getArraySeparator, getArrayStart, getContentEnd, getContentStart, getFieldNameValueSeparator, getFieldSeparator, getNullText, getShortClassName, getSizeEndText, getSizeStartText, getSummaryObjectEndText, getSummaryObjectStartText, isArrayContentDetail, isDefaultFullDetail, isFieldSeparatorAtEnd, isFieldSeparatorAtStart, isFullDetail, isUseClassName, isUseFieldNames, isUseIdentityHashCode, isUseShortClassName, reflectionAppendArrayDetail, removeLastFieldSeparator, setArrayContentDetail, setArrayEnd, setArraySeparator, setArrayStart, setContentEnd, setContentStart, setDefaultFullDetail, setFieldNameValueSeparator, setFieldSeparator, setFieldSeparatorAtEnd, setFieldSeparatorAtStart, setNullText, setSizeEndText, setSizeStartText, setSummaryObjectEndText, setSummaryObjectStartText, setUseClassName, setUseFieldNames, setUseIdentityHashCode, setUseShortClassName
public RecursiveToStringStyle()
Constructor.
public void appendDetail(StringBuffer buffer, String fieldName, Object value)
ToStringStyle
Append to the toString
an Object
value, printing the full detail of the Object
.
appendDetail
in class ToStringStyle
buffer
- the StringBuffer
to populatefieldName
- the field name, typically not used as already appendedvalue
- the value to add to the toString
,
not null
protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll)
ToStringStyle
Append to the toString
a Collection
.
appendDetail
in class ToStringStyle
buffer
- the StringBuffer
to populatefieldName
- the field name, typically not used as already appendedcoll
- the Collection
to add to the
toString
, not null
protected boolean accept(Class<?> clazz)
Class
.
By default, this method always returns true
, but may be overwritten by
sub-classes to filter specific classes.clazz
- The class to test.Class
.Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.