Class ObjectPrinter<T>

java.lang.Object
org.approvej.print.ObjectPrinter<T>
Type Parameters:
T - the type of the object to be printed
All Implemented Interfaces:
Function<T,String>, Printer<T>

@NullMarked public class ObjectPrinter<T> extends Object implements Printer<T>
A generic printer for Java Objects that prints their properties and values one per line.
  • Field Details

    • SIMPLE_TYPES

      public static final Set<Class<?>> SIMPLE_TYPES
      A Set of classes that will be printed directly.
  • Constructor Details

    • ObjectPrinter

      public ObjectPrinter()
      Creates a new ObjectPrinter instance that prints the given object.

      This constructor is public to allow instantiation via reflection, e.g. in the Configuration class.

  • Method Details

    • objectPrinter

      public static <T> ObjectPrinter<T> objectPrinter()
      Creates a new ObjectPrinter instance.
      Type Parameters:
      T - the type of the object to be printed
      Returns:
      a new ObjectPrinter instance
    • sorted

      public ObjectPrinter<T> sorted()
      Causes the Printer to sort the printed object's fields by their name. By default, the fields will be printed in the order of their declaration.
      Returns:
      this
    • apply

      public String apply(Object value)
      Specified by:
      apply in interface Function<T,String>