Class FormatAwareOutputParser<T>

java.lang.Object
com.tnsai.parser.FormatAwareOutputParser<T>
Type Parameters:
T - the target type
All Implemented Interfaces:
OutputParser<T>

public class FormatAwareOutputParser<T> extends Object implements OutputParser<T>
Output parser that supports multiple formats (JSON, YAML, TOON, TONL). Delegates to appropriate serializer based on configured format.

Usage:

 // For JSON output (default)
 OutputParser<User> parser = FormatAwareOutputParser.json(User.class);

 // For YAML output
 OutputParser<Spec> parser = FormatAwareOutputParser.yaml(Spec.class);

 // For token-optimized TOON format
 OutputParser<Report> parser = FormatAwareOutputParser.toon(Report.class);

 // Use with agent
 User user = agent.chatWithStructure("Get user info", parser, 3);
 
  • Constructor Details

    • FormatAwareOutputParser

      public FormatAwareOutputParser(Class<T> targetType, OutputFormat format)
      Creates a parser for single object output.
    • FormatAwareOutputParser

      public FormatAwareOutputParser(Class<T> targetType, OutputFormat format, boolean isListOutput)
      Creates a parser with list output option.
  • Method Details