Package ai.acolite.agentsdk.openai
Class SerializationUtils
java.lang.Object
ai.acolite.agentsdk.openai.SerializationUtils
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 Summary
Modifier and TypeMethodDescriptionstatic <T> TconvertViaJson(Object obj, Class<T> targetClass) Round-trip serialize-deserialize for type conversion.static ObjectdeserializeFromJson(String json) Deserialize JSON string to untyped Object (Map/List/primitive).static <T> TdeserializeFromJson(String json, Class<T> targetClass) Deserialize JSON string to an object of specified type.static StringserializeToJson(Object obj) Serialize an object to JSON string.
-
Method Details
-
serializeToJson
Serialize an object to JSON string.- Parameters:
obj- Object to serialize (can be null)- Returns:
- JSON string representation
-
deserializeFromJson
Deserialize JSON string to an object of specified type.- Type Parameters:
T- Type of target class- Parameters:
json- JSON string to parsetargetClass- Target class to deserialize into- Returns:
- Deserialized object
- Throws:
RuntimeException- if deserialization fails
-
deserializeFromJson
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
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 objecttargetClass- Target class to convert to- Returns:
- Converted object
- Throws:
RuntimeException- if conversion fails
-