Class JsonPrettyPrinter<T>

java.lang.Object
org.approvej.json.jackson.JsonPrettyPrinter<T>
Type Parameters:
T - the type of value to print
All Implemented Interfaces:
Function<T,String>, JsonPrinter<T>, org.approvej.print.Printer<T>

@NullMarked public class JsonPrettyPrinter<T> extends Object implements JsonPrinter<T>
A Printer that uses ObjectWriter.writeValueAsString(Object) to print a value as JSON.
  • Method Details

    • jsonPrettyPrinter

      public static <T> JsonPrettyPrinter<T> jsonPrettyPrinter(com.fasterxml.jackson.databind.ObjectWriter objectWriter)
      Creates a JsonPrettyPrinter using the given ObjectWriter.
      Type Parameters:
      T - the type of value to print
      Parameters:
      objectWriter - the ObjectWriter that will be used for printing
      Returns:
      a new JsonPrettyPrinter instance
    • jsonPrettyPrinter

      public static <T> JsonPrettyPrinter<T> jsonPrettyPrinter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Creates a JsonPrettyPrinter using the given ObjectMapper.
      Type Parameters:
      T - the type of value to print
      Parameters:
      objectMapper - the ObjectMapper used to create the ObjectWriter
      Returns:
      a new JsonPrettyPrinter instance
      See Also:
      • ObjectMapper.writerWithDefaultPrettyPrinter()
    • jsonPrettyPrinter

      public static <T> JsonPrettyPrinter<T> jsonPrettyPrinter()
      Creates a JsonPrettyPrinter using the default JsonMapper.
      Type Parameters:
      T - the type of value to print
      Returns:
      a new JsonPrettyPrinter instance
      See Also:
      • MapperBuilder.build()
    • apply

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