public class TypeAdapterManager extends Object
register(Type, TypeAdapter)
注册。register(TypeAdapter)
注册。管理器的使用分为两种方式:
getInstance()
调用单例,全局可用。of()
创建实例,局部可用,不加载默认的转换器。Constructor and Description |
---|
TypeAdapterManager()
构造
|
Modifier and Type | Method and Description |
---|---|
JSONDeserializer<Object> |
getDeserializer(JSON json,
Type type)
获取匹配器对应的反序列化器
|
static TypeAdapterManager |
getInstance()
获得单例的 TypeAdapterManager
|
JSONSerializer<Object> |
getSerializer(Object bean,
Type type)
获取匹配器对应的序列化器
|
static TypeAdapterManager |
of()
创建空的TypeAdapterManager
|
TypeAdapterManager |
register(TypeAdapter typeAdapter)
注册自定义类型适配器,用于自定义对象序列化和反序列化
提供的适配器必须为实现 MatcherJSONSerializer 或MatcherJSONDeserializer 接口当两个接口都实现时,同时注册序列化和反序列化器 |
TypeAdapterManager |
register(Type type,
TypeAdapter typeAdapter)
注册自定义类型适配器,用于自定义对象序列化和反序列化
|
public static TypeAdapterManager getInstance()
public static TypeAdapterManager of()
public TypeAdapterManager register(TypeAdapter typeAdapter)
MatcherJSONSerializer
或MatcherJSONDeserializer
接口typeAdapter
- 自定义类型适配器public TypeAdapterManager register(Type type, TypeAdapter typeAdapter)
type
- 类型typeAdapter
- 自定义序列化器,null
表示移除public JSONSerializer<Object> getSerializer(Object bean, Type type)
bean
- 对象type
- 类型public JSONDeserializer<Object> getDeserializer(JSON json, Type type)
json
- JSON, 单独查找强类型匹配传null
type
- 类型, 单独查匹配器传null
Copyright © 2025. All rights reserved.