Class JacksonUtils
java.lang.Object
uno.anahata.ai.internal.JacksonUtils
A generic utility class for Jackson-based JSON operations.
This class uses the centrally configured ObjectMapper from
SchemaProvider2 to ensure consistency in how Java objects are
mapped to JSON across the application, especially for tool parameters
and responses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TconvertMapToObject(Map<String, Object> map, Class<T> clazz) Deserializes aMap<String, Object>back into a specific POJO type.convertObjectToMap(String primitiveFieldName, Object o) Converts an object to aMap<String, Object>, replicating the logic required by the GeminiFunctionResponsetype.static <T> TconvertValue(Object object, Type type) Deserializes a generic object (typically a Map or List of Maps) back into a specific type, including complex generic types.
-
Constructor Details
-
JacksonUtils
public JacksonUtils()
-
-
Method Details
-
convertObjectToMap
Converts an object to aMap<String, Object>, replicating the logic required by the GeminiFunctionResponsetype.- If the object naturally serializes to a JSON Object (e.g., a POJO or a Map), it is
converted into a
Map<String, Object>. - If the object serializes to any other JSON type (e.g., an array, a string, a number), it is wrapped in a Map under the given field name.
- Parameters:
primitiveFieldName- The key to use when wrapping a non-POJO type.o- The object to convert.- Returns:
- A Map representation of the object, ready for use in a FunctionResponse.
- If the object naturally serializes to a JSON Object (e.g., a POJO or a Map), it is
converted into a
-
convertMapToObject
Deserializes aMap<String, Object>back into a specific POJO type.- Type Parameters:
T- The target type.- Parameters:
map- The map to convert.clazz- The class of the target type.- Returns:
- An instance of the target type, or
nullif the input map is null or empty.
-
convertValue
Deserializes a generic object (typically a Map or List of Maps) back into a specific type, including complex generic types.- Type Parameters:
T- The target type.- Parameters:
object- The object to convert (typically a Map or List of Maps).type- The target type, which can be aClassor aParameterizedType.- Returns:
- An instance of the target type, or
nullif the input object is null.
-
