Class RecursiveToStringStyle

java.lang.Object
org.aoju.bus.core.builder.ToStringStyle
org.aoju.bus.core.builder.RecursiveToStringStyle
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MultilineToStringStyle

public class RecursiveToStringStyle extends ToStringStyle
使用ToStringBuilder创建一个"deep" toString
 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();
   }
 }
 
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • RecursiveToStringStyle

      public RecursiveToStringStyle()
  • Method Details

    • appendDetail

      public void appendDetail(StringBuffer buffer, String fieldName, Object value)
      Description copied from class: ToStringStyle

      Append to the toString an Object value, printing the full detail of the Object.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      value - the value to add to the toString, not null
    • appendDetail

      protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll)
      Description copied from class: ToStringStyle

      Append to the toString a Collection.

      Overrides:
      appendDetail in class ToStringStyle
      Parameters:
      buffer - the StringBuffer to populate
      fieldName - the field name, typically not used as already appended
      coll - the Collection to add to the toString, not null
    • accept

      protected boolean accept(Class<?> clazz)
      返回是否递归格式化给定的Class。默认情况下,这个方法总是返回true, 但是可能会被子类覆盖以过滤特定的类.
      Parameters:
      clazz - 要测试的类.
      Returns:
      是否递归格式化给定的Class.