public class MapConverter extends ConverterWithRoot implements MatcherConverter, Serializable
Map 转换器,通过预定义key和value的类型,实现:
| Modifier and Type | Field and Description |
|---|---|
static MapConverter |
INSTANCE
单例
|
rootConverter| Constructor and Description |
|---|
MapConverter(Converter rootConverter)
构造
|
| Modifier and Type | Method and Description |
|---|---|
Object |
convert(Type targetType,
Object value)
转换为指定类型
如果类型无法确定,将读取默认值的类型做为目标类型 |
Map<?,?> |
convert(Type targetType,
Type keyType,
Type valueType,
Object value)
转换对象为指定键值类型的指定类型Map
|
boolean |
match(Type targetType,
Class<?> rawType,
Object value)
判断需要转换的对象是否匹配当前转换器,满足则转换,否则跳过
|
getRootConverterclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmatchpublic static final MapConverter INSTANCE
public MapConverter(Converter rootConverter)
rootConverter - 根转换器,用于转换Map中键值对中的值,非nullpublic boolean match(Type targetType, Class<?> rawType, Object value)
MatcherConvertermatch in interface MatcherConvertertargetType - 转换的目标类型,不能为nullrawType - 目标原始类型,当targetType为Class时,和此参数一致,不能为nullvalue - 需要转换的值public Object convert(Type targetType, Object value) throws ConvertException
Converterconvert in interface ConvertertargetType - 目标Type,非泛型类使用value - 原始值,如果对象实现了此接口,则value为thisConvertException - 转换无法正常完成或转换异常时抛出此异常public Map<?,?> convert(Type targetType, Type keyType, Type valueType, Object value) throws ConvertException
targetType - 目标的Map类型keyType - 键类型valueType - 值类型value - 被转换的值ConvertException - 转换异常或不支持的类型Copyright © 2025. All rights reserved.