类 RuntimeTypeAdapterFactory<T>

java.lang.Object
com.example.renderer.util.RuntimeTypeAdapterFactory<T>
类型参数:
T - 基类型
所有已实现的接口:
com.google.gson.TypeAdapterFactory

public class RuntimeTypeAdapterFactory<T> extends Object implements com.google.gson.TypeAdapterFactory
运行时类型适配器工厂类
  • 方法详细资料

    • of

      public static <T> RuntimeTypeAdapterFactory<T> of(Class<T> baseType, String typeFieldName)
      创建运行时类型适配器工厂
      类型参数:
      T - 基类型
      参数:
      baseType - 基类
      typeFieldName - JSON中的类型字段名
      返回:
      适配器工厂实例
    • registerSubtype

      public RuntimeTypeAdapterFactory<T> registerSubtype(Class<? extends T> type, String label)
      注册子类型
      参数:
      type - 子类型类对象
      label - 类型标签
      返回:
      适配器工厂实例(用于链式调用)
    • create

      public <R> com.google.gson.TypeAdapter<R> create(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<R> type)
      指定者:
      create 在接口中 com.google.gson.TypeAdapterFactory