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


Java TypeToken.getRawType方法代码示例

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


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

示例1: getConstructor

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

示例2: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // we use a runtime check to make sure the 'T's equal
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
  if (typeToken.getRawType() != Timestamp.class) {
    return null;
  }

  final TypeAdapter<Date> dateTypeAdapter = gson.getAdapter(Date.class);
  return (TypeAdapter<T>) new TypeAdapter<Timestamp>() {
    @Override public Timestamp read(JsonReader in) throws IOException {
      Date date = dateTypeAdapter.read(in);
      return date != null ? new Timestamp(date.getTime()) : null;
    }

    @Override public void write(JsonWriter out, Timestamp value) throws IOException {
      dateTypeAdapter.write(out, value);
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:TypeAdapters.java

示例3: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
    if (typeToken.getRawType() != Timestamp.class) {
        return null;
    }
    final TypeAdapter<Date> dateTypeAdapter = gson.getAdapter(Date.class);
    return new TypeAdapter<Timestamp>() {
        public Timestamp read(JsonReader in) throws IOException {
            Date date = (Date) dateTypeAdapter.read(in);
            return date != null ? new Timestamp(date.getTime()) : null;
        }

        public void write(JsonWriter out, Timestamp value) throws IOException {
            dateTypeAdapter.write(out, value);
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:TypeAdapters.java

示例4: getActualTypeArguments

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
/** creates a map that maps generic type argument names to type tokens */
private static Map<String, TypeToken> getActualTypeArguments(TypeToken<?> typeToken) {
  Class<?> rawClass = typeToken.getRawType();
  Type type = typeToken.getType();
  TypeVariable<? extends Class<?>>[] typeParameters = rawClass.getTypeParameters();
  if (typeParameters==null || !(type instanceof ParameterizedType)) {
    return null;
  }
  Map<String, TypeToken> genericTypes = new HashMap<>();
  ParameterizedType parameterizedType = (ParameterizedType) type;
  Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
  for (int i=0; i<typeParameters.length; i++) {
    String typeParameterName = typeParameters[i].getName();
    TypeToken<?> actualType = TypeToken.get(actualTypeArguments[i]);
    genericTypes.put(typeParameterName, actualType);
  }
  return genericTypes;
}
 
开发者ID:rockscript,项目名称:rockscript,代码行数:19,代码来源:PolymorphicTypeAdapter.java

示例5: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    Class<?> rawType = type.getRawType();
    TypeAdapter<Map> mapAdapter = gson.getAdapter(Map.class);
    TypeAdapter<Collection> collectionAdapter = gson.getAdapter(Collection.class);
    if (Location.class.isAssignableFrom(rawType)) {
        return (TypeAdapter<T>) new LocationTypeAdapter();
    } else if (ConfigurationSerializable.class.isAssignableFrom(rawType)) {
        return (TypeAdapter<T>) new ConfigurationSerializableAdapter(mapAdapter);
    } else if (GUISignature.class.isAssignableFrom(rawType)) {
        return (TypeAdapter<T>) new GUISignatureTypeAdapter(mapAdapter, collectionAdapter);
    } else if (MaterialAndData.class.isAssignableFrom(rawType)) {
        return (TypeAdapter<T>) new MaterialAndDataAdapter();
    }
    return null;
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:17,代码来源:BukkitTypeAdapterFactory.java

示例6: responseBodyConverter

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
    TypeToken<?> typeToken = TypeToken.get(type);
    if (typeToken.getRawType() == JSONObject.class) {
        return new JsonResponseBodyConverter<JSONObject>();
    } else if (typeToken.getRawType() == JSONArray.class) {
        return new JsonArrayResponseBodyConverter<JSONArray>();
    } else {
        try {
            throw new Throwable("非法类型");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return null;
        }
    }

}
 
开发者ID:killnono,项目名称:Dalaran,代码行数:18,代码来源:XJsonConverterFactory.java

示例7: typeName

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public PolymorphicTypeAdapterFactory typeName(TypeToken<?> type, String name) {
  typeNames.put(type, name);

  matchingTypes.add(type);
  Class<?> rawClass = type.getRawType();
  TypeToken<?> rawType = TypeToken.get(rawClass);
  if (!rawType.equals(type)) {
    matchingTypes.add(rawType);
  }

  return this;
}
 
开发者ID:rockscript,项目名称:rockscript,代码行数:13,代码来源:PolymorphicTypeAdapterFactory.java

示例8: newFactory

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public static <TT> TypeAdapterFactory newFactory(final Class<TT> unboxed, final Class<TT> boxed, final TypeAdapter<? super TT> typeAdapter) {
    return new TypeAdapterFactory() {
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
            Class<? super T> rawType = typeToken.getRawType();
            return (rawType == unboxed || rawType == boxed) ? typeAdapter : null;
        }

        public String toString() {
            return "Factory[type=" + boxed.getName() + "+" + unboxed.getName() + ",adapter=" + typeAdapter + "]";
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:13,代码来源:TypeAdapters.java

示例9: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, final TypeToken<T> type) {
  Class<? super T> raw = type.getRawType();

  if (!Object.class.isAssignableFrom(raw)) {
    return null; // it's a primitive!
  }

  ObjectConstructor<T> constructor = constructorConstructor.get(type);
  return new Adapter<T>(constructor, getBoundFields(gson, type, raw));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:ReflectiveTypeAdapterFactory.java

示例10: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    if(Enum.class.isAssignableFrom(type.getRawType())) {
        return (TypeAdapter<T>) new StrictEnumTypeAdapter(type.getRawType());
    }
    return null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:StrictEnumTypeAdapter.java

示例11: 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();
    if (!raw.isInterface()) {
        Type declaredType = type.getType();
        while (raw != Object.class) {
            for (Field field : raw.getDeclaredFields()) {
                boolean serialize = excludeField(field, true);
                boolean deserialize = excludeField(field, false);
                if (serialize || deserialize) {
                    field.setAccessible(true);
                    BoundField boundField = createBoundField(context, field, getFieldName
                            (field), TypeToken.get(C$Gson$Types.resolve(type.getType(), raw,
                            field.getGenericType())), serialize, deserialize);
                    BoundField previous = (BoundField) result.put(boundField.name, boundField);
                    if (previous != null) {
                        throw new IllegalArgumentException(declaredType + " declares multiple" +
                                " JSON fields named " + previous.name);
                    }
                }
            }
            type = TypeToken.get(C$Gson$Types.resolve(type.getType(), raw, raw
                    .getGenericSuperclass()));
            raw = type.getRawType();
        }
    }
    return result;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:ReflectiveTypeAdapterFactory.java

示例12: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public final <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type){
	Class<T> rawType = (Class<T>)type.getRawType();
	boolean hasOptionals = Arrays.stream(rawType.getDeclaredFields())
			.filter(field -> !Modifier.isStatic(field.getModifiers()))
			.anyMatch(field -> field.getType() == Optional.class);
	return hasOptionals ? (TypeAdapter<T>)getClassAdapter(gson, type) : null;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:10,代码来源:OptionalContainerClassTypeAdapterFactory.java

示例13: newFactoryForMultipleTypes

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public static <TT> TypeAdapterFactory newFactoryForMultipleTypes(final Class<TT> base, final Class<? extends TT> sub, final TypeAdapter<? super TT> typeAdapter) {
    return new TypeAdapterFactory() {
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
            Class<? super T> rawType = typeToken.getRawType();
            return (rawType == base || rawType == sub) ? typeAdapter : null;
        }

        public String toString() {
            return "Factory[type=" + base.getName() + "+" + sub.getName() + ",adapter=" + typeAdapter + "]";
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:13,代码来源:TypeAdapters.java

示例14: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    boolean matches = this.exactType != null ? this.exactType.equals(type) || (this
            .matchRawType && this.exactType.getType() == type.getRawType()) : this
            .hierarchyType.isAssignableFrom(type.getRawType());
    if (matches) {
        return new TreeTypeAdapter(this.serializer, this.deserializer, gson, type, this);
    }
    return null;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:TreeTypeAdapter.java

示例15: create

import com.google.gson.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
  Class<?> rawType = type.getRawType();
  final boolean skipSerialize = excludeClass(rawType, true);
  final boolean skipDeserialize = excludeClass(rawType, false);

  if (!skipSerialize && !skipDeserialize) {
    return null;
  }

  return new TypeAdapter<T>() {
    /** The delegate is lazily created because it may not be needed, and creating it may fail. */
    private TypeAdapter<T> delegate;

    @Override public T read(JsonReader in) throws IOException {
      if (skipDeserialize) {
        in.skipValue();
        return null;
      }
      return delegate().read(in);
    }

    @Override public void write(JsonWriter out, T value) throws IOException {
      if (skipSerialize) {
        out.nullValue();
        return;
      }
      delegate().write(out, value);
    }

    private TypeAdapter<T> delegate() {
      TypeAdapter<T> d = delegate;
      return d != null
          ? d
          : (delegate = gson.getDelegateAdapter(Excluder.this, type));
    }
  };
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:38,代码来源:Excluder.java


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