org.apache.myfaces.trinidad.util

## Class ToStringHelper

- java.lang.Object
- - org.apache.myfaces.trinidad.util.ToStringHelper

-     public final class ToStringHelper
      extends Object

  Helper class to build strings for diagnostic log messages which benefit from detailed information, and in toString() implementations. This class takes care of few niceties like: 1. Adding the identity (classname and hashcode) of an object 2. Adding fields and values of an object, ensuring null value fields are excluded 3. Formatting the string in JSON style 4. Adopts a builder pattern, hence easy to use Note that this class is intended to be used in a single thread and is not thread safe. Example use: `public class CustomClass { private String fieldOne = "HELLO"; private Object fieldTwo = null; private boolean fieldThree = false; private List fieldFour = new ArrayList(Arrays.asList("one","two","three")); public String toString() { return new ToStringHelper(this). append("fieldOne", fieldOne). append("fieldTwo", fieldTwo). append("fieldThree", fieldThree). append("fieldFour", fieldFour). toString(); } }` Return value of toString() in above example will be "CustomClass@19621457 {fieldOne: HELLO, fieldThree: false, fieldFour: [one, two, three]} "

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ToStringHelper()`
    `ToStringHelper(Object object)` Constructor that takes in the object whose information is to be added to the string

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ToStringHelper` | `append(String fieldName, Object value)` Appends the field name and value (as returned by 'toString()' of the supplied value object), formatting it in JSON style
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ToStringHelper

          public ToStringHelper()

    - #### ToStringHelper

          public ToStringHelper(Object object)

      Constructor that takes in the object whose information is to be added to the string
      Parameters:
        `object` - The object whose classname and hashcode is to be included in the string

  - ### Method Detail

    - #### append

          public ToStringHelper append(String fieldName,
                              Object value)

      Appends the field name and value (as returned by 'toString()' of the supplied value object), formatting it in JSON style
      Parameters:
        `fieldName` - The name of the field to append
        `value` - The value object of the field to append
      Returns:
        The helper object after appending

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.