Package com.tnsai.output.impl
Class JsonOutputSerializer
java.lang.Object
com.tnsai.output.AbstractOutputSerializer
com.tnsai.output.impl.JsonOutputSerializer
- All Implemented Interfaces:
OutputSerializer
JSON output serializer using Jackson.
Provides standard JSON serialization with configurable pretty-printing.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Tdeserialize(String data, Class<T> targetClass) Deserializes a string to an object of the specified type.<T> List<T> deserializeList(String data, Class<T> itemClass) Deserializes a string to a list of objects.getFormatInstructions(Class<?> targetClass) Generates format instructions for LLM to produce output in this format.getListFormatInstructions(Class<?> itemClass) Generates format instructions for list output.Serializes an object to the target format.<T> StringserializeList(List<T> items, Class<T> itemClass, boolean prettyPrint) Serializes a list of objects optimized for tabular formats.Methods inherited from class com.tnsai.output.AbstractOutputSerializer
getFormat, supportsTypeMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.output.OutputSerializer
serialize, serializeList
-
Constructor Details
-
JsonOutputSerializer
public JsonOutputSerializer()
-
-
Method Details
-
serialize
Description copied from interface:OutputSerializerSerializes an object to the target format.- Parameters:
data- the object to serializeprettyPrint- whether to format output for readability- Returns:
- the serialized string representation
-
serializeList
Description copied from interface:OutputSerializerSerializes 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
Description copied from interface:OutputSerializerDeserializes a string to an object of the specified type.- Type Parameters:
T- the target type- Parameters:
data- the serialized stringtargetClass- the target class- Returns:
- the deserialized object
-
deserializeList
Description copied from interface:OutputSerializerDeserializes a string to a list of objects.- Type Parameters:
T- the item type- Parameters:
data- the serialized stringitemClass- the class of list items- Returns:
- the deserialized list
-
getFormatInstructions
Description copied from interface:OutputSerializerGenerates 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
Description copied from interface:OutputSerializerGenerates format instructions for list output.- Parameters:
itemClass- the expected item class- Returns:
- format instructions string
-