AS AgentScopeAPI 手册 / API Reference

JsonUtils

public final class JsonUtils
源码Source io/agentscope/core/util/JsonUtils.java:49–152

JSON Utils,为框架提供通用类型与基础能力。位于 io.agentscope.core.util 包。核心成员包括 getJsonCodec、setJsonCodec、resetToDefault、isValidJsonObject、resolveToolCallArgsJson。

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());
`

方法摘要Method Summary

方法Method说明Description
public static JsonCodec getJsonCodec()
static
获取JSON 编解码器。
Get the global JsonCodec instance.
public static void setJsonCodec(JsonCodec jsonCodec)
static
设置JSON 编解码器。
Set a custom JsonCodec implementation.
public static void resetToDefault()
static
重置到默认。
Reset to the default JacksonJsonCodec implementation.
public static boolean isValidJsonObject(String str)
static
判断是否有效 JSON 对象。
Check whether the given string is a valid JSON object (i.e.
public static String resolveToolCallArgsJson(ToolUseBlock toolUse)
static
解析工具调用参数 JSON。
Resolve the arguments JSON string from a `ToolUseBlock`, ensuring the result is always a valid JSON object.

方法详情Method Detail

getJsonCodec

public static JsonCodec getJsonCodec()
static

获取JSON 编解码器。

Get the global JsonCodec instance.

返回Returns JsonCodec
JsonCodec 实例。the JsonCodec instance
源码Source io/agentscope/core/util/JsonUtils.java:64–66

setJsonCodec

public static void setJsonCodec(JsonCodec jsonCodec)
static

设置JSON 编解码器。

Set a custom JsonCodec implementation.

参数Parameters
名称Name类型Type说明Description
jsonCodecJsonCodecJSON 编解码器(类型 `JsonCodec`)。the custom JsonCodec implementation
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if jsonCodec is null
源码Source io/agentscope/core/util/JsonUtils.java:77–82

resetToDefault

public static void resetToDefault()
static

重置到默认。

Reset to the default JacksonJsonCodec implementation.

源码Source io/agentscope/core/util/JsonUtils.java:89–91

isValidJsonObject

public static boolean isValidJsonObject(String str)
static

判断是否有效 JSON 对象。

Check whether the given string is a valid JSON object (i.e.

参数Parameters
名称Name类型Type说明Description
strStringstr(类型 `String`)。the string to validate
返回Returns boolean
返回布尔值,表示判断结果。`true` if `str` is a non-null, parseable JSON object
源码Source io/agentscope/core/util/JsonUtils.java:103–114

resolveToolCallArgsJson

public static String resolveToolCallArgsJson(ToolUseBlock toolUse)
static

解析工具调用参数 JSON。

Resolve the arguments JSON string from a ToolUseBlock, ensuring the result is always a valid JSON object.

参数Parameters
名称Name类型Type说明Description
toolUseToolUseBlock工具使用块。the tool use block
返回Returns String
返回字符串结果。a valid JSON object string representing the tool call arguments
源码Source io/agentscope/core/util/JsonUtils.java:133–151
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.