类 DsonConverterUtils

java.lang.Object
cn.wjybxx.dsoncodec.DsonConverterUtils

public final class DsonConverterUtils extends Object
作者:
wjybxx date 2023/4/4
  • 构造器详细资料

    • DsonConverterUtils

      public DsonConverterUtils()
  • 方法详细资料

    • arrayRankSymbol

      public static String arrayRankSymbol(int rank)
    • getRootComponentType

      public static Class<?> getRootComponentType(Class<?> clz)
      获取根元素的类型 -- 如果Type是数组,则返回最底层的元素类型;如果不是数组,则返回type
    • getArrayRank

      public static int getArrayRank(Class<?> clz)
      获取数组的阶数 -- 如果不是数组,则返回0
    • canInheritTypeArgs

      public static <T> boolean canInheritTypeArgs(Class<T> encoderClass, TypeInfo<?> typeInfo)
      判断要编码的类型是否可继承声明类型的泛型参数
    • canInheritTypeArgs

      public static <T> boolean canInheritTypeArgs(Class<T> thisClass, Class<?> targetClass)
      测试当前类是否可继承目标类的泛型参数
    • getElementActualTypeInfo

      public static <T> TypeInfo<?> getElementActualTypeInfo(Class<T> rawType)
      获取传递给集合的元素类型;不存在则返回nuLl
    • getKeyActualTypeInfo

      public static <T> TypeInfo<?> getKeyActualTypeInfo(Class<T> rawType)
      获取传递给字典的Key类型;不存在则返回nuLl
    • getDefaultCodecRegistry

      public static DsonCodecRegistry getDefaultCodecRegistry()
      获取默认的编解码器
    • getDefaultTypeMetaRegistry

      public static TypeMetaRegistry getDefaultTypeMetaRegistry()
      获取默认的元数据注册表
    • getDefaultValue

      public static Object getDefaultValue(Class<?> type)
      获取给定类型的默认值
    • boxIfPrimitiveType

      public static Class<?> boxIfPrimitiveType(Class<?> type)
    • unboxIfWrapperType

      public static Class<?> unboxIfWrapperType(Class<?> type)
    • isBoxType

      public static boolean isBoxType(Class<?> type)
    • isPrimitiveType

      public static boolean isPrimitiveType(Class<?> type)
    • isAssignable

      public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType)
      测试右手边的类型是否可以赋值给左边的类型。 基本类型和其包装类型之间将认为是可赋值的。
      参数:
      lhsType - 基类型
      rhsType - 测试的类型
      返回:
      如果测试的类型可以赋值给基类型则返回true,否则返回false
    • isAssignableValue

      public static boolean isAssignableValue(Class<?> type, @Nullable Object value)
      测试给定的值是否可以赋值给定的类型。 基本类型和其包装类型之间将认为是可赋值的,但null值不可以赋值给基本类型。
      参数:
      type - 目标类型
      value - 测试的值
      返回:
      如果目标值可以赋值给目标类型则返回true
    • castValue

      public static <T> T castValue(Class<T> type, Object value)
      java.lang.ClassCastException: Cannot cast java.lang.Integer to int Class.cast(Object)对基本类型有坑。。。。
    • getEncodeClass

      public static Class<?> getEncodeClass(Object value)
      枚举实例可能是枚举类的子类,如果枚举实例声明了代码块{},在编解码时需要转换为声明类
    • isEncodeAsArray

      public static <T> boolean isEncodeAsArray(Class<T> encoderClass)
      注意:默认情况下map是一个数组对象,而不是普通的对象
    • convertList2Array

      public static <T, E> T convertList2Array(List<? extends E> list, Class<T> arrayType)
      List转Array
    • noArgConstructorToSupplier

      public static <T> Supplier<T> noArgConstructorToSupplier(MethodHandles.Lookup lookup, Constructor<T> constructor) throws Throwable
      无参构造函数转lambda实例 -- 可避免解码过程中的反射
      抛出:
      Throwable
    • createCollectionCodec

      public static <T extends Collection<?>> CollectionCodec<T> createCollectionCodec(MethodHandles.Lookup lookup, Class<T> clazz)
      参数:
      lookup - 外部缓存实例,避免每次创建的开销
    • createMapCodec

      public static <T extends Map<?, ?>> MapCodec<T> createMapCodec(MethodHandles.Lookup lookup, Class<T> clazz)