Class SerializationUtils

java.lang.Object
ai.acolite.agentsdk.openai.SerializationUtils

public class SerializationUtils extends Object
SerializationUtils

Static utility methods for JSON serialization/deserialization. Shared across all SDK components for consistent JSON handling.

Uses a single configured ObjectMapper with: - FAIL_ON_UNKNOWN_PROPERTIES=false for API resilience

  • Method Details

    • serializeToJson

      public static String serializeToJson(Object obj)
      Serialize an object to JSON string.
      Parameters:
      obj - Object to serialize (can be null)
      Returns:
      JSON string representation
    • deserializeFromJson

      public static <T> T deserializeFromJson(String json, Class<T> targetClass)
      Deserialize JSON string to an object of specified type.
      Type Parameters:
      T - Type of target class
      Parameters:
      json - JSON string to parse
      targetClass - Target class to deserialize into
      Returns:
      Deserialized object
      Throws:
      RuntimeException - if deserialization fails
    • deserializeFromJson

      public static Object deserializeFromJson(String json)
      Deserialize JSON string to untyped Object (Map/List/primitive).
      Parameters:
      json - JSON string to parse
      Returns:
      Deserialized object (Map, List, String, Number, Boolean, or null)
    • convertViaJson

      public static <T> T convertViaJson(Object obj, Class<T> targetClass)
      Round-trip serialize-deserialize for type conversion.

      Useful for converting Map to typed object, or converting between compatible types. Uses JSON as intermediate format.

      Type Parameters:
      T - Type of target class
      Parameters:
      obj - Source object
      targetClass - Target class to convert to
      Returns:
      Converted object
      Throws:
      RuntimeException - if conversion fails