Class StreamingJacksonOutputConverter
-
- All Implemented Interfaces:
-
org.springframework.ai.converter.FormatProvider,org.springframework.ai.converter.StructuredOutputConverter,org.springframework.core.convert.converter.Converter
public final class StreamingJacksonOutputConverter<T extends Object> extends FilteringJacksonOutputConverter<T>
Streaming output converter that extends FilteringJacksonOutputConverter to support JSONL format.
This converter enables streaming LLM responses by:
Converting JSONL (JSON Lines) input to reactive Flux<T> streams of typed objects
Supporting mixed content streams with both objects and thinking content via StreamingEvent<T>
Inheriting JSON schema injection and property filtering capabilities from parent FilteringJacksonOutputConverter
Providing instructions to LLMs for proper JSONL output formatting
Use cases:
Streaming lists of objects from LLM responses in real-time
Processing LLM reasoning (thinking) alongside structured outputs
Real-time agent progress monitoring and incremental results
The converter requests JSONL format from LLMs and parses each line as a separate JSON object, emitting them as reactive stream events as they become available.
-
-
Field Summary
Fields Modifier and Type Field Description private final StringjsonSchemaprivate final ObjectMapperobjectMapper
-
Constructor Summary
Constructors Constructor Description StreamingJacksonOutputConverter(Class<T> clazz, ObjectMapper objectMapper, Predicate<String> propertyFilter)StreamingJacksonOutputConverter(ParameterizedTypeReference<T> typeReference, ObjectMapper objectMapper, Predicate<String> propertyFilter)
-
Method Summary
Modifier and Type Method Description final Flux<T>convertStream(String jsonlContent)Convert streaming JSONL text to a Flux of typed objects. final Flux<StreamingEvent<T>>convertStreamWithThinking(String text)Convert streaming text with thinking blocks into StreamingEvent objects. StringgetFormat()Override format to request JSONL instead of single JSON. -
Methods inherited from class com.embabel.common.ai.converters.JacksonOutputConverter
convert, getJsonSchema, getObjectMapper -
Methods inherited from class org.springframework.core.convert.converter.Converter
andThen -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
convertStream
final Flux<T> convertStream(String jsonlContent)
Convert streaming JSONL text to a Flux of typed objects. Each line should be a valid JSON object matching the schema. Uses resilient error handling - logs warnings for null conversions but continues processing other lines.
-
convertStreamWithThinking
final Flux<StreamingEvent<T>> convertStreamWithThinking(String text)
Convert streaming text with thinking blocks into StreamingEvent objects. Supports both object lines and thinking blocks. Uses resilient error handling - logs warnings for individual line failures but continues processing.
-
-
-
-