Class FlatWeaver

java.lang.Object
com.robinloom.jweaver.flat.FlatWeaver
All Implemented Interfaces:
Weaver

public class FlatWeaver extends Object implements Weaver
DynamicWeaver generates a string representation for a given object by combining the object information (class name, field names, values) with a set of separator strings. The set of separator strings is dynamically configurable.

Example:

Person[name=John Doe, birthday=1990-01-01]
  • Field Details

  • Constructor Details

    • FlatWeaver

      public FlatWeaver()
  • Method Details

    • multiline

      public FlatWeaver multiline()
      Sets newline '\n' as separator for fields and for classname and fields. The result will be a multiline output.
      Returns:
      instance for chaining
    • classNamePrefix

      public FlatWeaver classNamePrefix(String classNamePrefix)
      Sets a string to be placed before the class name. Default is empty string.
      Parameters:
      classNamePrefix - the string to use
      Returns:
      instance for chaining
    • classNameSuffix

      public FlatWeaver classNameSuffix(String classNameSuffix)
      Sets a string to be placed after the class name. Default is empty string.
      Parameters:
      classNameSuffix - the string to use
      Returns:
      instance for chaining
    • classNameFieldsSeparator

      public FlatWeaver classNameFieldsSeparator(String separator)
      Sets a string to separate the class name and the fields to be printed. Will be between the class name suffix and the first field. Default string is "[".
      Parameters:
      separator - the separator string to use
      Returns:
      instance for chaining
    • fieldValueSeparator

      public FlatWeaver fieldValueSeparator(String separator)
      Sets a string to separate the field name and the corresponding value. Default string is "=".
      Parameters:
      separator - the separator string to use
      Returns:
      instance for chaining
    • fieldSeparator

      public FlatWeaver fieldSeparator(String separator)
      Sets a string that is used to separate the printed fields. Default string is ","
      Parameters:
      separator - the separator string to use.
      Returns:
      instance for chaining
    • globalSuffix

      public FlatWeaver globalSuffix(String suffix)
      Sets a string that is placed at the end of the generated string. Default string is "]".
      Parameters:
      suffix - the string to be used.
      Returns:
      instance for chaining.
    • maxSequenceLength

      public FlatWeaver maxSequenceLength(int maxSequenceLength)
      Sets the maximum length of collections and arrays to be included in the output. Elements that exceed the limit will be summarized (... 57 more).
      Parameters:
      maxSequenceLength - an integer value
      Returns:
      instance for chaining
    • includeFields

      public FlatWeaver includeFields(List<String> fields)
      Sets the names of fields that should be included in the output. By default, every field is included.
      Parameters:
      fields - list of strings containing included field names
      Returns:
      instance for chaining
    • excludeFields

      public FlatWeaver excludeFields(List<String> fields)
      Sets the names of fields that should be excluded from the output. By default, no field is excluded.
      Parameters:
      fields - list of strings containing excluded field names
      Returns:
      instance for chaining
    • omitClassName

      public FlatWeaver omitClassName()
      Determines if the class name should be omitted when printing. By default, the class name is included.
      Returns:
      instance for chaining
    • capitalizeFields

      public FlatWeaver capitalizeFields()
      Enables capitalization of field names. firstName -> FirstName
      Returns:
      instance for chaining
    • showDataTypes

      public FlatWeaver showDataTypes()
      Enables the printing of data types
      Returns:
      instance for chaining
    • showInheritedFields

      public FlatWeaver showInheritedFields()
      Activates the inclusion of inherited fields.
      Returns:
      instance for chaining
    • orderFieldsAlphabetically

      public FlatWeaver orderFieldsAlphabetically()
      Will order field names alphabetically before printing.
      Returns:
      instance for chaining
    • weave

      public String weave(Object object)
      Generates a string representation of the given object via reflections. Prints the class name followed by every accessible field. For JDK classes, a regular toString() result is returned. Detects reciprocal and circular object dependencies.
      Specified by:
      weave in interface Weaver
      Parameters:
      object - object to generate a string representation for
      Returns:
      a well-structured, human-readable representation of that object