Class JacksonUtils

java.lang.Object
uno.anahata.ai.internal.JacksonUtils

public final class JacksonUtils extends Object
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 Details

    • JacksonUtils

      public JacksonUtils()
  • Method Details

    • convertObjectToMap

      public static Map<String,Object> convertObjectToMap(String primitiveFieldName, Object o)
      Converts an object to a Map<String, Object>, replicating the logic required by the Gemini FunctionResponse type.
      • 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.
    • convertMapToObject

      public static <T> T convertMapToObject(Map<String,Object> map, Class<T> clazz)
      Deserializes a Map<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 null if the input map is null or empty.
    • convertValue

      public static <T> T convertValue(Object object, Type type)
      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 a Class or a ParameterizedType.
      Returns:
      An instance of the target type, or null if the input object is null.