Package com.agui.json
Class AGUIJacksonSerializer
java.lang.Object
com.agui.json.AGUIJacksonSerializer
- All Implemented Interfaces:
com.agui.community.core.serialization.Serializer
- Direct Known Subclasses:
AGUILangGraphStudioJacksonSerializer
public class AGUIJacksonSerializer
extends Object
implements com.agui.community.core.serialization.Serializer
Jackson-based implementation of the AG-UI
Serializer protocol.
Configures a Jackson ObjectMapper suited to (de)serialize AG-UI core model classes
(events, messages, interrupt/resume outcomes, enums with a JSON value, ...) to/from JSON,
registering the required mixins (EventMixin, MessageMixin, OutcomeMixin,
ResumeMixin, EnumWithValueMixin) only if not already present, and relaxing
deserialization so unknown properties are ignored and only non-null properties are serialized.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.fasterxml.jackson.databind.ObjectMapper -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new serializer, building and configuring the underlying JacksonObjectMapperwith the mixins required to handle AG-UI core model classes. -
Method Summary
Modifier and TypeMethodDescription<T> Tdeserialize(String json, Class<T> type) Deserializes the given JSON string into an instance of the given type.<T> List<T> deserializeList(String json, Class<T> elementType) Deserializes the given JSON string into a list of elements of the given type.com.fasterxml.jackson.databind.ObjectMapperReturns the underlying JacksonObjectMapperused for serialization and deserialization.Serializes the given value to its JSON string representation.voidserializeAttributes(@Nullable Map<String, Object> attributes) Sets the attributes to be used during serialization.
-
Field Details
-
objectMapper
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
-
-
Constructor Details
-
AGUIJacksonSerializer
public AGUIJacksonSerializer()Creates a new serializer, building and configuring the underlying JacksonObjectMapperwith the mixins required to handle AG-UI core model classes.
-
-
Method Details
-
objectMapper
public com.fasterxml.jackson.databind.ObjectMapper objectMapper()Returns the underlying JacksonObjectMapperused for serialization and deserialization.- Returns:
- the configured
ObjectMapper
-
serializeAttributes
-
serialize
Serializes the given value to its JSON string representation.- Specified by:
serializein interfacecom.agui.community.core.serialization.Serializer- Parameters:
value- the object to serialize- Returns:
- the JSON representation of
value - Throws:
RuntimeException- if serialization fails
-
deserialize
Deserializes the given JSON string into an instance of the given type.- Specified by:
deserializein interfacecom.agui.community.core.serialization.Serializer- Type Parameters:
T- the target type- Parameters:
json- the JSON string to deserializetype- the target type- Returns:
- the deserialized instance
- Throws:
RuntimeException- if deserialization fails
-
deserializeList
Deserializes the given JSON string into a list of elements of the given type.- Specified by:
deserializeListin interfacecom.agui.community.core.serialization.Serializer- Type Parameters:
T- the type of the list elements- Parameters:
json- the JSON string to deserializeelementType- the type of the list elements- Returns:
- the deserialized list
- Throws:
RuntimeException- if deserialization fails
-