类 JacksonJsonCodec
java.lang.Object
io.agentscope.core.util.JacksonJsonCodec
- 所有已实现的接口:
JsonCodec
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.
- 另请参阅:
-
构造器概要
构造器构造器说明Creates a new JacksonJsonCodec with default ObjectMapper configuration.JacksonJsonCodec(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a new JacksonJsonCodec with a custom ObjectMapper. -
方法概要
修饰符和类型方法说明<T> TconvertValue(Object from, com.fasterxml.jackson.core.type.TypeReference<T> toTypeRef) Convert an object to another generic type.<T> TconvertValue(Object from, Class<T> toType) Convert an object to another type.convertValue(Object from, Type toType) Convert an object to another type using Java reflection Type.<T> TDeserialize a JSON string to an object with generic type.<T> TDeserialize a JSON string to an object of the specified type.com.fasterxml.jackson.databind.ObjectMapperGet the underlying ObjectMapper for advanced operations.Serialize an object to JSON string.toPrettyJson(Object obj) Serialize an object to pretty-printed JSON string.
-
构造器详细资料
-
JacksonJsonCodec
public JacksonJsonCodec()Creates a new JacksonJsonCodec with default ObjectMapper configuration. -
JacksonJsonCodec
public JacksonJsonCodec(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a new JacksonJsonCodec with a custom ObjectMapper.- 参数:
objectMapper- the ObjectMapper to use
-
-
方法详细资料
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Get the underlying ObjectMapper for advanced operations.- 返回:
- the ObjectMapper instance
-
toJson
从接口复制的说明:JsonCodecSerialize an object to JSON string. -
toPrettyJson
从接口复制的说明:JsonCodecSerialize an object to pretty-printed JSON string.- 指定者:
toPrettyJson在接口中JsonCodec- 参数:
obj- the object to serialize- 返回:
- pretty-printed JSON string representation
-
fromJson
从接口复制的说明:JsonCodecDeserialize a JSON string to an object of the specified type. -
fromJson
从接口复制的说明:JsonCodecDeserialize a JSON string to an object with generic type.Use this method when deserializing to generic types like
List<MyClass>. -
convertValue
从接口复制的说明:JsonCodecConvert an object to another type.This is useful for converting Map to typed objects or vice versa.
- 指定者:
convertValue在接口中JsonCodec- 类型参数:
T- the type parameter- 参数:
from- the source objecttoType- the target class type- 返回:
- converted object
-
convertValue
从接口复制的说明:JsonCodecConvert an object to another generic type.- 指定者:
convertValue在接口中JsonCodec- 类型参数:
T- the type parameter- 参数:
from- the source objecttoTypeRef- the type reference for generic types- 返回:
- converted object
-
convertValue
从接口复制的说明:JsonCodecConvert an object to another type using Java reflection Type.This method preserves generic type information from parameterized types such as
List<MyClass>orMap<String, MyClass>.Example usage:
// For a method parameter declared as List<OrderItem> Type paramType = parameter.getParameterizedType(); List<OrderItem> items = (List<OrderItem>) codec.convertValue(value, paramType);- 指定者:
convertValue在接口中JsonCodec- 参数:
from- the source objecttoType- the target type (can be Class, ParameterizedType, etc.)- 返回:
- converted object
-