Class YamlPrinter<T>

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

@NullMarked public class YamlPrinter<T> extends Object implements org.approvej.print.Printer<T>
A Printer that uses ObjectWriter.writeValueAsString(Object) to print a value as YAML.
  • Constructor Details

    • YamlPrinter

      public YamlPrinter(com.fasterxml.jackson.databind.ObjectWriter objectWriter)
      Creates a YamlPrinter using the given ObjectWriter.
      Parameters:
      objectWriter - the ObjectWriter that will be used for printing
    • YamlPrinter

      public YamlPrinter()
      Creates a YamlPrinter using the default YAMLMapper.
  • Method Details

    • yamlPrinter

      public static <T> YamlPrinter<T> yamlPrinter(com.fasterxml.jackson.databind.ObjectWriter objectWriter)
      Creates a YamlPrinter 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 YamlPrinter instance
    • yamlPrinter

      public static <T> YamlPrinter<T> yamlPrinter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Creates a YamlPrinter 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 YamlPrinter instance
      See Also:
      • ObjectMapper.writerWithDefaultPrettyPrinter()
    • yamlPrinter

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

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

      public String filenameExtension()
      Specified by:
      filenameExtension in interface org.approvej.print.Printer<T>