当前位置: 首页>>代码示例>>Java>>正文


Java TypeToken.getType方法代码示例

本文整理汇总了Java中com.google.gson.reflect.TypeToken.getType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeToken.getType方法的具体用法?Java TypeToken.getType怎么用?Java TypeToken.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.reflect.TypeToken的用法示例。


在下文中一共展示了TypeToken.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
  Type type = typeToken.getType();

  Class<? super T> rawType = typeToken.getRawType();
  if (!Map.class.isAssignableFrom(rawType)) {
    return null;
  }

  Class<?> rawTypeOfSrc = $Gson$Types.getRawType(type);
  Type[] keyAndValueTypes = $Gson$Types.getMapKeyAndValueTypes(type, rawTypeOfSrc);
  TypeAdapter<?> keyAdapter = getKeyAdapter(gson, keyAndValueTypes[0]);
  TypeAdapter<?> valueAdapter = gson.getAdapter(TypeToken.get(keyAndValueTypes[1]));
  ObjectConstructor<T> constructor = constructorConstructor.get(typeToken);

  @SuppressWarnings({"unchecked", "rawtypes"})
  // we don't define a type parameter for the key or value types
  TypeAdapter<T> result = new Adapter(gson, keyAndValueTypes[0], keyAdapter,
      keyAndValueTypes[1], valueAdapter, constructor);
  return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:MapTypeAdapterFactory.java

示例2: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
    Type type = typeToken.getType();
    if (!Map.class.isAssignableFrom(typeToken.getRawType())) {
        return null;
    }
    Type[] keyAndValueTypes = C$Gson$Types.getMapKeyAndValueTypes(type, C$Gson$Types
            .getRawType(type));
    return new Adapter(gson, keyAndValueTypes[0], getKeyAdapter(gson, keyAndValueTypes[0]),
            keyAndValueTypes[1], gson.getAdapter(TypeToken.get(keyAndValueTypes[1])), this
            .constructorConstructor.get(typeToken));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:MapTypeAdapterFactory.java

示例3: get

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken) {
    final Type type = typeToken.getType();
    Class<? super T> rawType = typeToken.getRawType();
    final InstanceCreator<T> typeCreator = (InstanceCreator) this.instanceCreators.get(type);
    if (typeCreator != null) {
        return new ObjectConstructor<T>() {
            public T construct() {
                return typeCreator.createInstance(type);
            }
        };
    }
    final InstanceCreator<T> rawTypeCreator = (InstanceCreator) this.instanceCreators.get
            (rawType);
    if (rawTypeCreator != null) {
        return new ObjectConstructor<T>() {
            public T construct() {
                return rawTypeCreator.createInstance(type);
            }
        };
    }
    ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
    if (defaultConstructor != null) {
        return defaultConstructor;
    }
    ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(type,
            rawType);
    if (defaultImplementation != null) {
        return defaultImplementation;
    }
    return newUnsafeAllocator(type, rawType);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:32,代码来源:ConstructorConstructor.java

示例4: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
    Type type = typeToken.getType();
    if (!(type instanceof GenericArrayType) && (!(type instanceof Class) || !((Class) type).isArray())) {
        return null;
    }
    Type componentType = C$Gson$Types.getArrayComponentType(type);
    return new ArrayTypeAdapter(gson, gson.getAdapter(TypeToken.get(componentType)), C$Gson$Types.getRawType(componentType));
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:9,代码来源:ArrayTypeAdapter.java

示例5: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
    Type type = typeToken.getType();
    if (!Map.class.isAssignableFrom(typeToken.getRawType())) {
        return null;
    }
    Type[] keyAndValueTypes = C$Gson$Types.getMapKeyAndValueTypes(type, C$Gson$Types.getRawType(type));
    return new Adapter(gson, keyAndValueTypes[0], getKeyAdapter(gson, keyAndValueTypes[0]), keyAndValueTypes[1], gson.getAdapter(TypeToken.get(keyAndValueTypes[1])), this.constructorConstructor.getConstructor(typeToken));
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:9,代码来源:MapTypeAdapterFactory.java

示例6: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
    Type type = typeToken.getType();
    Class<? super T> rawType = typeToken.getRawType();
    if (!Collection.class.isAssignableFrom(rawType)) {
        return null;
    }
    Type elementType = C$Gson$Types.getCollectionElementType(type, rawType);
    return new Adapter(gson, elementType, gson.getAdapter(TypeToken.get(elementType)), this.constructorConstructor.getConstructor(typeToken));
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:10,代码来源:CollectionTypeAdapterFactory.java

示例7: getBoundFields

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
private Map<String, BoundField> getBoundFields(Gson context, TypeToken<?> type, Class<?> raw) {
  Map<String, BoundField> result = new LinkedHashMap<String, BoundField>();
  if (raw.isInterface()) {
    return result;
  }

  Type declaredType = type.getType();
  while (raw != Object.class) {
    Field[] fields = raw.getDeclaredFields();
    for (Field field : fields) {
      boolean serialize = excludeField(field, true);
      boolean deserialize = excludeField(field, false);
      if (!serialize && !deserialize) {
        continue;
      }
      field.setAccessible(true);
      Type fieldType = $Gson$Types.resolve(type.getType(), raw, field.getGenericType());
      BoundField boundField = createBoundField(context, field, getFieldName(field),
          TypeToken.get(fieldType), serialize, deserialize);
      BoundField previous = result.put(boundField.name, boundField);
      if (previous != null) {
        throw new IllegalArgumentException(declaredType
            + " declares multiple JSON fields named " + previous.name);
      }
    }
    type = TypeToken.get($Gson$Types.resolve(type.getType(), raw, raw.getGenericSuperclass()));
    raw = type.getRawType();
  }
  return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ReflectiveTypeAdapterFactory.java

示例8: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
    Type type = typeToken.getType();
    if (!(type instanceof GenericArrayType) && (!(type instanceof Class) || !((Class)
            type).isArray())) {
        return null;
    }
    Type componentType = C$Gson$Types.getArrayComponentType(type);
    return new ArrayTypeAdapter(gson, gson.getAdapter(TypeToken.get(componentType)),
            C$Gson$Types.getRawType(componentType));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:11,代码来源:ArrayTypeAdapter.java

示例9: getAsParsed

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public void getAsParsed(TypeToken typeToken, ParsedRequestListener parsedRequestListener) {
    this.mType = typeToken.getType();
    this.mResponseType = ResponseType.PARSED;
    this.mParsedRequestListener = parsedRequestListener;
    ANRequestQueue.getInstance().addRequest(this);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:ANRequest.java

示例10: getAsOkHttpResponseAndParsed

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public void getAsOkHttpResponseAndParsed(TypeToken typeToken, OkHttpResponseAndParsedRequestListener parsedRequestListener) {
    this.mType = typeToken.getType();
    this.mResponseType = ResponseType.PARSED;
    this.mOkHttpResponseAndParsedRequestListener = parsedRequestListener;
    ANRequestQueue.getInstance().addRequest(this);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:ANRequest.java

示例11: newFactoryWithMatchRawType

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public static TypeAdapterFactory newFactoryWithMatchRawType(TypeToken<?> exactType, Object
        typeAdapter) {
    return new SingleTypeFactory(typeAdapter, exactType, exactType.getType() == exactType
            .getRawType(), null);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:6,代码来源:TreeTypeAdapter.java

示例12: getTargetType

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
@Override
protected Type getTargetType() {
    TypeToken<Map<String, String>> typeToken = new TypeToken<Map<String, String>>() {};
    return typeToken.getType();
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:6,代码来源:MapAdaptor.java

示例13: newFactoryWithMatchRawType

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public static TypeAdapterFactory newFactoryWithMatchRawType(TypeToken<?> exactType, Object typeAdapter) {
    return new SingleTypeFactory(typeAdapter, exactType, exactType.getType() == exactType.getRawType(), null);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:4,代码来源:TreeTypeAdapter.java

示例14: getTargetType

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
@Override
protected Type getTargetType() {
    TypeToken<List<Throwable>> typeToken = new TypeToken<List<Throwable>>() {};
    return typeToken.getType();
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:6,代码来源:ListThrowableAdaptor.java

示例15: get

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken) {
  final Type type = typeToken.getType();
  final Class<? super T> rawType = typeToken.getRawType();

  // first try an instance creator

  @SuppressWarnings("unchecked") // types must agree
  final InstanceCreator<T> typeCreator = (InstanceCreator<T>) instanceCreators.get(type);
  if (typeCreator != null) {
    return new ObjectConstructor<T>() {
      public T construct() {
        return typeCreator.createInstance(type);
      }
    };
  }

  // Next try raw type match for instance creators
  @SuppressWarnings("unchecked") // types must agree
  final InstanceCreator<T> rawTypeCreator =
      (InstanceCreator<T>) instanceCreators.get(rawType);
  if (rawTypeCreator != null) {
    return new ObjectConstructor<T>() {
      public T construct() {
        return rawTypeCreator.createInstance(type);
      }
    };
  }

  ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
  if (defaultConstructor != null) {
    return defaultConstructor;
  }

  ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(type, rawType);
  if (defaultImplementation != null) {
    return defaultImplementation;
  }

  // finally try unsafe
  return newUnsafeAllocator(type, rawType);
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:42,代码来源:ConstructorConstructor.java


注:本文中的com.google.gson.reflect.TypeToken.getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。