public class ConverterRegistry extends Object implements Serializable
将各种类型Convert对象放入登记中心,通过convert方法查找目标类型对应的转换器,将被转换对象转换之。
在此类中,存放着默认转换器和自定义转换器,默认转换器是Hutool中预定义的一些转换器,自定义转换器存放用户自定的转换器。
| Constructor and Description |
|---|
ConverterRegistry()
构造
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
convert(Type type,
Object value)
转换值为指定类型
|
<T> T |
convert(Type type,
Object value,
T defaultValue)
转换值为指定类型
自定义转换器优先 |
<T> T |
convert(Type type,
Object value,
T defaultValue,
boolean isCustomFirst)
转换值为指定类型
|
<T> Converter<T> |
getConverter(Type type,
boolean isCustomFirst)
获得转换器
|
<T> Converter<T> |
getCustomConverter(Type type)
获得自定义转换器
|
<T> Converter<T> |
getDefaultConverter(Type type)
获得默认转换器
|
static ConverterRegistry |
getInstance()
获得单例的 ConverterRegistry
|
ConverterRegistry |
putCustom(Type type,
Class<? extends Converter<?>> converterClass)
登记自定义转换器
|
ConverterRegistry |
putCustom(Type type,
Converter<?> converter)
登记自定义转换器
|
public static ConverterRegistry getInstance()
public ConverterRegistry putCustom(Type type, Class<? extends Converter<?>> converterClass)
type - 转换的目标类型converterClass - 转换器类,必须有默认构造方法public ConverterRegistry putCustom(Type type, Converter<?> converter)
type - 转换的目标类型converter - 转换器public <T> Converter<T> getConverter(Type type, boolean isCustomFirst)
T - 转换的目标类型type - 类型isCustomFirst - 是否自定义转换器优先public <T> Converter<T> getDefaultConverter(Type type)
T - 转换的目标类型(转换器转换到的类型)type - 类型public <T> Converter<T> getCustomConverter(Type type)
T - 转换的目标类型(转换器转换到的类型)type - 类型public <T> T convert(Type type, Object value, T defaultValue, boolean isCustomFirst) throws ConvertException
T - 转换的目标类型(转换器转换到的类型)type - 类型目标value - 被转换值defaultValue - 默认值isCustomFirst - 是否自定义转换器优先ConvertException - 转换器不存在public <T> T convert(Type type, Object value, T defaultValue) throws ConvertException
T - 转换的目标类型(转换器转换到的类型)type - 类型value - 值defaultValue - 默认值ConvertException - 转换器不存在public <T> T convert(Type type, Object value) throws ConvertException
T - 转换的目标类型(转换器转换到的类型)type - 类型value - 值nullConvertException - 转换器不存在Copyright © 2025. All rights reserved.