JacksonJsonCodec
public class JacksonJsonCodec implements JsonCodec
io/agentscope/core/util/JacksonJsonCodec.java:44–152Jackson JSON 编解码器,为框架提供通用类型与基础能力。位于 io.agentscope.core.util 包,实现 JsonCodec。核心成员包括 getObjectMapper、toJson、toPrettyJson、fromJson、convertValue、JacksonJsonCodec。
Jackson-based implementation of JsonCodec.
This is the default implementation used by JsonUtils. It uses
Jackson's ObjectMapper with the following configuration:
FAIL_ON_UNKNOWN_PROPERTIES = false- allows unknown fields in JSON
Users can access the underlying ObjectMapper via #getObjectMapper()
for advanced operations not covered by the JsonCodec interface.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public JacksonJsonCodec() | 创建新的JacksonJsonCodec 使用默认 ObjectMapper 配置。 Creates a new JacksonJsonCodec with default ObjectMapper configuration. |
public JacksonJsonCodec(ObjectMapper objectMapper) | 创建新的JacksonJsonCodec 使用自定义 ObjectMapper。 Creates a new JacksonJsonCodec with a custom ObjectMapper. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public ObjectMapper getObjectMapper() | 获取 `getObjectMapper`。 Get the underlying ObjectMapper for advanced operations. |
public String toJson(Object obj) | 设置到 JSON。 Performs the to json operation. |
public String toPrettyJson(Object obj) | 设置该参数。 Performs the to pretty json operation. |
public T T fromJson(String json, Class<T> type) | 执行来自 JSON相关操作。 Performs the from json operation. |
public T T fromJson(String json, TypeReference<T> typeRef) | 执行来自 JSON相关操作。 Performs the from json operation. |
public T T convertValue(Object from, Class<T> toType) | 转换值。 Converts the value. |
public T T convertValue(Object from, TypeReference<T> toTypeRef) | 转换值。 Converts the value. |
public Object convertValue(Object from, Type toType) | 转换值。 Converts the value. |
构造器详情Constructor Detail
JacksonJsonCodec
public JacksonJsonCodec()
创建新的JacksonJsonCodec 使用默认 ObjectMapper 配置。
Creates a new JacksonJsonCodec with default ObjectMapper configuration.
io/agentscope/core/util/JacksonJsonCodec.java:53–55JacksonJsonCodec
public JacksonJsonCodec(ObjectMapper objectMapper)
创建新的JacksonJsonCodec 使用自定义 ObjectMapper。
Creates a new JacksonJsonCodec with a custom ObjectMapper.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
objectMapper | ObjectMapper | ObjectMapper 到使用。the ObjectMapper to use |
io/agentscope/core/util/JacksonJsonCodec.java:62–64方法详情Method Detail
getObjectMapper
public ObjectMapper getObjectMapper()
获取 getObjectMapper。
Get the underlying ObjectMapper for advanced operations.
ObjectMapperio/agentscope/core/util/JacksonJsonCodec.java:83–85toJson
public String toJson(Object obj)
设置到 JSON。
Performs the to json operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
obj | Object | obj(类型 `Object`)。The obj. |
Stringio/agentscope/core/util/JacksonJsonCodec.java:87–95toPrettyJson
public String toPrettyJson(Object obj)
设置该参数。
Performs the to pretty json operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
obj | Object | obj(类型 `Object`)。The obj. |
Stringio/agentscope/core/util/JacksonJsonCodec.java:97–105fromJson
public T T fromJson(String json, Class<T> type)
执行来自 JSON相关操作。
Performs the from json operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
json | String | JSON(类型 `String`)。The json. |
type | Class<T> | 类型(类型 `Class`)。The type. |
Tio/agentscope/core/util/JacksonJsonCodec.java:107–114fromJson
public T T fromJson(String json, TypeReference<T> typeRef)
执行来自 JSON相关操作。
Performs the from json operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
json | String | JSON(类型 `String`)。The json. |
typeRef | TypeReference<T> | 类型引用(类型 `TypeReference`)。The type ref. |
Tio/agentscope/core/util/JacksonJsonCodec.java:116–123convertValue
public T T convertValue(Object from, Class<T> toType)
转换值。
Converts the value.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
from | Object | 来自(类型 `Object`)。The from. |
toType | Class<T> | 到类型(类型 `Class`)。The to type. |
Tio/agentscope/core/util/JacksonJsonCodec.java:125–132convertValue
public T T convertValue(Object from, TypeReference<T> toTypeRef)
转换值。
Converts the value.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
from | Object | 来自(类型 `Object`)。The from. |
toTypeRef | TypeReference<T> | 到类型引用(类型 `TypeReference`)。The to type ref. |
Tio/agentscope/core/util/JacksonJsonCodec.java:134–141convertValue
public Object convertValue(Object from, Type toType)
转换值。
Converts the value.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
from | Object | 来自(类型 `Object`)。The from. |
toType | Type | 到类型(类型 `Type`)。The to type. |
Objectio/agentscope/core/util/JacksonJsonCodec.java:143–151