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 SchemaProvider to ensure consistency in how Java objects are mapped to JSON across the application, especially for tool parameters and responses.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static Object
    Converts any object into its JSON-safe equivalent (Map, List, or Primitive) using the centrally configured ObjectMapper.
    static <T> T
    toPojo(Object object, Type type)
    Converts a JSON-safe object (Map, List, or Primitive) back into a rich Java object of the specified type.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JacksonUtils

      public JacksonUtils()
  • Method Details

    • toJsonPrimitives

      public static Object toJsonPrimitives(Object o)
      Converts any object into its JSON-safe equivalent (Map, List, or Primitive) using the centrally configured ObjectMapper. This ensures that all POJOs are flattened and custom serializers (like ElementHandleModule) are applied.
      Parameters:
      o - The object to convert.
      Returns:
      The JSON-safe representation of the object.
    • toPojo

      public static <T> T toPojo(Object object, Type type)
      Converts a JSON-safe object (Map, List, or Primitive) back into a rich Java object of the specified type.
      Type Parameters:
      T - The target type.
      Parameters:
      object - The JSON-safe object to convert.
      type - The target type.
      Returns:
      An instance of the target type.
    • 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.