Class YamlOutputSerializer

java.lang.Object
com.tnsai.output.AbstractOutputSerializer
com.tnsai.output.impl.YamlOutputSerializer
All Implemented Interfaces:
OutputSerializer

public class YamlOutputSerializer extends AbstractOutputSerializer
YAML output serializer. Produces human-readable YAML output without external dependencies.

Features:

  • Indentation-based nesting
  • Multi-line string support
  • Compact list notation where appropriate
  • Constructor Details

    • YamlOutputSerializer

      public YamlOutputSerializer()
  • Method Details

    • serialize

      public String serialize(Object data, boolean prettyPrint)
      Description copied from interface: OutputSerializer
      Serializes an object to the target format.
      Parameters:
      data - the object to serialize
      prettyPrint - whether to format output for readability
      Returns:
      the serialized string representation
    • serializeList

      public <T> String serializeList(List<T> items, Class<T> itemClass, boolean prettyPrint)
      Description copied from interface: OutputSerializer
      Serializes a list of objects optimized for tabular formats. For formats like TOON, TONL, CSV this produces more efficient output.
      Type Parameters:
      T - the item type
      Parameters:
      items - the list of objects (should be uniform type)
      itemClass - the class of list items (for schema inference)
      prettyPrint - whether to format output for readability
      Returns:
      the serialized string representation
    • deserialize

      public <T> T deserialize(String data, Class<T> targetClass)
      Description copied from interface: OutputSerializer
      Deserializes a string to an object of the specified type.
      Type Parameters:
      T - the target type
      Parameters:
      data - the serialized string
      targetClass - the target class
      Returns:
      the deserialized object
    • deserializeList

      public <T> List<T> deserializeList(String data, Class<T> itemClass)
      Description copied from interface: OutputSerializer
      Deserializes a string to a list of objects.
      Type Parameters:
      T - the item type
      Parameters:
      data - the serialized string
      itemClass - the class of list items
      Returns:
      the deserialized list
    • getFormatInstructions

      public String getFormatInstructions(Class<?> targetClass)
      Description copied from interface: OutputSerializer
      Generates format instructions for LLM to produce output in this format. Used in prompts to guide LLM response formatting.
      Parameters:
      targetClass - the expected output class (for schema hints)
      Returns:
      format instructions string
    • getListFormatInstructions

      public String getListFormatInstructions(Class<?> itemClass)
      Description copied from interface: OutputSerializer
      Generates format instructions for list output.
      Parameters:
      itemClass - the expected item class
      Returns:
      format instructions string