类 JsonUtils
java.lang.Object
io.agentscope.core.util.JsonUtils
Utility class for accessing the global
JsonCodec instance.
This class provides a centralized way to access JSON serialization/deserialization
functionality throughout the framework. By default, it uses JacksonJsonCodec,
but users can replace it with a custom implementation.
Usage:
// Basic usage
JsonUtils.getJsonCodec().toJson(obj);
JsonUtils.getJsonCodec().fromJson(json, MyClass.class);
// Cache reference for frequent calls
JsonCodec codec = JsonUtils.getJsonCodec();
codec.toJson(obj1);
codec.toJson(obj2);
// Replace with custom implementation
JsonUtils.setJsonCodec(new MyCustomJsonCodec());
- 另请参阅:
-
方法概要
修饰符和类型方法说明static JsonCodecGet the global JsonCodec instance.static voidReset to the default JacksonJsonCodec implementation.static voidsetJsonCodec(JsonCodec jsonCodec) Set a custom JsonCodec implementation.
-
方法详细资料
-
getJsonCodec
Get the global JsonCodec instance.- 返回:
- the JsonCodec instance
-
setJsonCodec
Set a custom JsonCodec implementation.This allows users to replace the default Jackson-based implementation with their own implementation (e.g., Gson, Fastjson, etc.).
- 参数:
jsonCodec- the custom JsonCodec implementation- 抛出:
IllegalArgumentException- if jsonCodec is null
-
resetToDefault
public static void resetToDefault()Reset to the default JacksonJsonCodec implementation.This is useful for testing or when you want to restore the default behavior.
-