JsonSchemaUtils
public class JsonSchemaUtils
io/agentscope/core/util/JsonSchemaUtils.java:62–182JSON 模式 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)
设置该参数。
Generate JSON Schema from a Java class.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
clazz | Class<?> | clazz(类型 `Class`)。The class to generate schema for |
Map<String, Object>RuntimeException可能抛出 `RuntimeException`。if schema generation fails due to reflection errors, configuration issues, or other processing errors
io/agentscope/core/util/JsonSchemaUtils.java:107–118generateSchemaFromJsonNode
public static Map<String, Object> generateSchemaFromJsonNode(JsonNode schema)
设置该参数。
Generate JSON Schema from a com.fasterxml.jackson.databind.JsonNode instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
schema | JsonNode | 模式定义(类型 `JsonNode`)。The com.fasterxml.jackson.databind.JsonNode instance to generate schema for |
Map<String, Object>RuntimeException可能抛出 `RuntimeException`。if schema generation fails due to reflection errors, configuration issues, or other processing errors
io/agentscope/core/util/JsonSchemaUtils.java:130–137generateSchemaFromType
public static Map<String, Object> generateSchemaFromType(Type type)
设置该参数。
Generate JSON Schema from a Java Type (supports Generics).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | Type | 类型(类型 `Type`)。The type to generate schema for |
Map<String, Object>io/agentscope/core/util/JsonSchemaUtils.java:145–157convertToObject
public static T T convertToObject(Object data, Class<T> targetClass)
转换到对象。
Convert Map to typed object.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
data | Object | 数据映射。The data map |
targetClass | Class<T> | 目标类。The target class |
TIllegalStateException可能抛出 `IllegalStateException`。if the input data is nullRuntimeException可能抛出 `RuntimeException`。if the conversion fails due to type mismatch, JSON parsing errors, or incompatible data structure
io/agentscope/core/util/JsonSchemaUtils.java:171–181