AS AgentScopeAPI 手册 / API Reference

JacksonJsonCodec

public class JacksonJsonCodec implements JsonCodec
源码Source io/agentscope/core/util/JacksonJsonCodec.java:44–152

Jackson 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.

源码Source io/agentscope/core/util/JacksonJsonCodec.java:53–55

JacksonJsonCodec

public JacksonJsonCodec(ObjectMapper objectMapper)

创建新的JacksonJsonCodec 使用自定义 ObjectMapper。

Creates a new JacksonJsonCodec with a custom ObjectMapper.

参数Parameters
名称Name类型Type说明Description
objectMapperObjectMapperObjectMapper 到使用。the ObjectMapper to use
源码Source io/agentscope/core/util/JacksonJsonCodec.java:62–64

方法详情Method Detail

getObjectMapper

public ObjectMapper getObjectMapper()

获取 getObjectMapper。

Get the underlying ObjectMapper for advanced operations.

返回Returns ObjectMapper
ObjectMapper 实例。the ObjectMapper instance
源码Source io/agentscope/core/util/JacksonJsonCodec.java:83–85

toJson

public String toJson(Object obj)

设置到 JSON。

Performs the to json operation.

参数Parameters
名称Name类型Type说明Description
objObjectobj(类型 `Object`)。The obj.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/util/JacksonJsonCodec.java:87–95

toPrettyJson

public String toPrettyJson(Object obj)

设置该参数。

Performs the to pretty json operation.

参数Parameters
名称Name类型Type说明Description
objObjectobj(类型 `Object`)。The obj.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/util/JacksonJsonCodec.java:97–105

fromJson

public T T fromJson(String json, Class<T> type)

执行来自 JSON相关操作。

Performs the from json operation.

参数Parameters
名称Name类型Type说明Description
jsonStringJSON(类型 `String`)。The json.
typeClass<T>类型(类型 `Class`)。The type.
返回Returns T
返回T。Returns t.
源码Source io/agentscope/core/util/JacksonJsonCodec.java:107–114

fromJson

public T T fromJson(String json, TypeReference<T> typeRef)

执行来自 JSON相关操作。

Performs the from json operation.

参数Parameters
名称Name类型Type说明Description
jsonStringJSON(类型 `String`)。The json.
typeRefTypeReference<T>类型引用(类型 `TypeReference`)。The type ref.
返回Returns T
返回T。Returns t.
源码Source io/agentscope/core/util/JacksonJsonCodec.java:116–123

convertValue

public T T convertValue(Object from, Class<T> toType)

转换值。

Converts the value.

参数Parameters
名称Name类型Type说明Description
fromObject来自(类型 `Object`)。The from.
toTypeClass<T>到类型(类型 `Class`)。The to type.
返回Returns T
返回T。Returns t.
源码Source io/agentscope/core/util/JacksonJsonCodec.java:125–132

convertValue

public T T convertValue(Object from, TypeReference<T> toTypeRef)

转换值。

Converts the value.

参数Parameters
名称Name类型Type说明Description
fromObject来自(类型 `Object`)。The from.
toTypeRefTypeReference<T>到类型引用(类型 `TypeReference`)。The to type ref.
返回Returns T
返回T。Returns t.
源码Source io/agentscope/core/util/JacksonJsonCodec.java:134–141

convertValue

public Object convertValue(Object from, Type toType)

转换值。

Converts the value.

参数Parameters
名称Name类型Type说明Description
fromObject来自(类型 `Object`)。The from.
toTypeType到类型(类型 `Type`)。The to type.
返回Returns Object
返回对象。Returns object.
源码Source io/agentscope/core/util/JacksonJsonCodec.java:143–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.