类 ConverterRegistry

java.lang.Object
com.alibaba.ageiport.common.convert.ConverterRegistry
所有已实现的接口:
Serializable

public class ConverterRegistry extends Object implements Serializable
转换器登记中心

将各种类型Convert对象放入登记中心,通过convert方法查找目标类型对应的转换器,将被转换对象转换之。

在此类中,存放着默认转换器和自定义转换器,默认转换器预定义的一些转换器,自定义转换器存放用户自定的转换器。

作者:
xuechao.sxc
另请参阅:
  • 构造器详细资料

    • ConverterRegistry

      public ConverterRegistry()
  • 方法详细资料

    • getInstance

      public static ConverterRegistry getInstance()
      获得单例的 ConverterRegistry
      返回:
      ConverterRegistry
    • putCustom

      public ConverterRegistry putCustom(Type type, Class<? extends Converter<?>> converterClass)
      登记自定义转换器
      参数:
      type - 转换的目标类型
      converterClass - 转换器类,必须有默认构造方法
      返回:
      ConverterRegistry
    • putCustom

      public ConverterRegistry putCustom(Type type, Converter<?> converter)
      登记自定义转换器
      参数:
      type - 转换的目标类型
      converter - 转换器
      返回:
      ConverterRegistry
    • getConverter

      public <T> Converter<T> getConverter(Type type, boolean isCustomFirst)
      获得转换器
      类型参数:
      T - 转换的目标类型
      参数:
      type - 类型
      isCustomFirst - 是否自定义转换器优先
      返回:
      转换器
    • getDefaultConverter

      public <T> Converter<T> getDefaultConverter(Type type)
      获得默认转换器
      类型参数:
      T - 转换的目标类型(转换器转换到的类型)
      参数:
      type - 类型
      返回:
      转换器
    • getCustomConverter

      public <T> Converter<T> getCustomConverter(Type type)
      获得自定义转换器
      类型参数:
      T - 转换的目标类型(转换器转换到的类型)
      参数:
      type - 类型
      返回:
      转换器
    • convert

      public <T> T convert(Type type, Object value, T defaultValue, boolean isCustomFirst) throws ConvertException
      转换值为指定类型
      类型参数:
      T - 转换的目标类型(转换器转换到的类型)
      参数:
      type - 类型目标
      value - 被转换值
      defaultValue - 默认值
      isCustomFirst - 是否自定义转换器优先
      返回:
      转换后的值
      抛出:
      ConvertException - 转换器不存在
    • convert

      public <T> T convert(Type type, Object value, T defaultValue) throws ConvertException
      转换值为指定类型
      自定义转换器优先
      类型参数:
      T - 转换的目标类型(转换器转换到的类型)
      参数:
      type - 类型
      value - 值
      defaultValue - 默认值
      返回:
      转换后的值
      抛出:
      ConvertException - 转换器不存在
    • convert

      public <T> T convert(Type type, Object value) throws ConvertException
      转换值为指定类型
      类型参数:
      T - 转换的目标类型(转换器转换到的类型)
      参数:
      type - 类型
      value - 值
      返回:
      转换后的值,默认为null
      抛出:
      ConvertException - 转换器不存在