AS AgentScopeAPI 手册 / API Reference

JsonSchemaUtils

public class JsonSchemaUtils
源码Source io/agentscope/core/util/JsonSchemaUtils.java:62–182

JSON 模式 Utils,为框架提供通用类型与基础能力。位于 io.agentscope.core.util 包。核心成员包括 generateSchemaFromClass、generateSchemaFromJsonNode、generateSchemaFromType、convertToObject。

Utility class for JSON Schema operations.

This class provides utility methods for:

  • Generating JSON schemas from Java classes (for structured output)

  • Converting between Maps and typed objects

  • Mapping Java types to JSON Schema types

Supports AgentScope annotations:

  • @ToolParam(description = ...) - add property description

  • @ToolParam(required = ...) - mark property as required

Supports Jackson annotations:

  • @JsonProperty(required = ...) - mark property as required

  • @JsonPropertyDescription(...) - add property description

  • @JsonClassDescription(...) - add class description

All public methods are thread-safe. Schema generation through the shared victools SchemaGenerator is serialized by an internal lock, because the generator itself is not designed for concurrent use.

方法摘要Method Summary

方法Method说明Description
public static Map<String, Object> generateSchemaFromClass(Class<?> clazz)
static
设置该参数。
Generate JSON Schema from a Java class.
public static Map<String, Object> generateSchemaFromJsonNode(JsonNode schema)
static
设置该参数。
Generate JSON Schema from a com.fasterxml.jackson.databind.JsonNode instance.
public static Map<String, Object> generateSchemaFromType(Type type)
static
设置该参数。
Generate JSON Schema from a Java Type (supports Generics).
public static T T convertToObject(Object data, Class<T> targetClass)
static
转换到对象。
Convert Map to typed object.

方法详情Method Detail

generateSchemaFromClass

public static Map<String, Object> generateSchemaFromClass(Class<?> clazz)
static

设置该参数。

Generate JSON Schema from a Java class.

参数Parameters
名称Name类型Type说明Description
clazzClass<?>clazz(类型 `Class`)。The class to generate schema for
返回Returns Map<String, Object>
返回映射。JSON Schema as a Map
抛出Throws
  • RuntimeException 可能抛出 `RuntimeException`。if schema generation fails due to reflection errors, configuration issues, or other processing errors
源码Source io/agentscope/core/util/JsonSchemaUtils.java:107–118

generateSchemaFromJsonNode

public static Map<String, Object> generateSchemaFromJsonNode(JsonNode schema)
static

设置该参数。

Generate JSON Schema from a com.fasterxml.jackson.databind.JsonNode instance.

参数Parameters
名称Name类型Type说明Description
schemaJsonNode模式定义(类型 `JsonNode`)。The com.fasterxml.jackson.databind.JsonNode instance to generate schema for
返回Returns Map<String, Object>
返回映射。JSON Schema as a Map
抛出Throws
  • RuntimeException 可能抛出 `RuntimeException`。if schema generation fails due to reflection errors, configuration issues, or other processing errors
源码Source io/agentscope/core/util/JsonSchemaUtils.java:130–137

generateSchemaFromType

public static Map<String, Object> generateSchemaFromType(Type type)
static

设置该参数。

Generate JSON Schema from a Java Type (supports Generics).

参数Parameters
名称Name类型Type说明Description
typeType类型(类型 `Type`)。The type to generate schema for
返回Returns Map<String, Object>
返回映射。JSON Schema as a Map
源码Source io/agentscope/core/util/JsonSchemaUtils.java:145–157

convertToObject

public static T T convertToObject(Object data, Class<T> targetClass)
static

转换到对象。

Convert Map to typed object.

参数Parameters
名称Name类型Type说明Description
dataObject数据映射。The data map
targetClassClass<T>目标类。The target class
返回Returns T
返回T。Converted object
抛出Throws
  • IllegalStateException 可能抛出 `IllegalStateException`。if the input data is null
  • RuntimeException 可能抛出 `RuntimeException`。if the conversion fails due to type mismatch, JSON parsing errors, or incompatible data structure
源码Source io/agentscope/core/util/JsonSchemaUtils.java:171–181
基于官方固定版本源码静态生成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.