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


Java Primitives.isPrimitive方法代码示例

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


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

示例1: registerTypeAdapter

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
    boolean z = (typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof InstanceCreator) || (typeAdapter instanceof TypeAdapter);
    C$Gson$Preconditions.checkArgument(z);
    if (Primitives.isPrimitive(type) || Primitives.isWrapperType(type)) {
        throw new IllegalArgumentException("Cannot register type adapters for " + type);
    }
    if (typeAdapter instanceof InstanceCreator) {
        this.instanceCreators.put(type, (InstanceCreator) typeAdapter);
    }
    if ((typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer)) {
        this.factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(TypeToken.get(type), typeAdapter));
    }
    if (typeAdapter instanceof TypeAdapter) {
        this.factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter) typeAdapter));
    }
    return this;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:GsonBuilder.java

示例2: deserialize

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override public MyParameterizedType<T> deserialize(JsonElement json, Type typeOfT,
    JsonDeserializationContext context) throws JsonParseException {
  Type genericClass = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
  Class<?> rawType = $Gson$Types.getRawType(genericClass);
  String className = rawType.getSimpleName();
  JsonElement jsonElement = json.getAsJsonObject().get(className);

  T value;
  if (genericClass == Integer.class) {
    value = (T) Integer.valueOf(jsonElement.getAsInt());
  } else if (genericClass == String.class) {
    value = (T) jsonElement.getAsString();
  } else {
    value = (T) jsonElement;
  }

  if (Primitives.isPrimitive(genericClass)) {
    PrimitiveTypeAdapter typeAdapter = new PrimitiveTypeAdapter();
    value = (T) typeAdapter.adaptType(value, rawType);
  }
  return new MyParameterizedType<T>(value);
}
 
开发者ID:osonus,项目名称:oson,代码行数:24,代码来源:ParameterizedTypeFixtures.java

示例3: FieldAttributeModel

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
/**
 * Build a new field model based on the name and Java type
 *
 * @param fieldName the name of the field
 * @param type the Java raw type that will allow further analyzes
 */
public FieldAttributeModel(String fieldName, Type type) {
  this.fieldName = fieldName;
  this.type = type;
  this.typeName = convertType(type);

  if (typeName.startsWith("Array<") || typeName.startsWith("Map<")) {
    this.needInitialize = true;
  }

  if (this.type instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) this.type;
    Type rawType = parameterizedType.getRawType();
    analyzeParametrizedType(parameterizedType, rawType);
  } else if (Primitives.isPrimitive(this.type)
      || Primitives.isWrapperType(this.type)
      || String.class.equals(this.type)) {
    this.isPrimitive = true;
  } else if (this.type instanceof Class && ((Class) this.type).isAnnotationPresent(DTO.class)) {
    this.isDto = true;
    dtoImpl = this.type.getTypeName() + "Impl";
  } else if (this.type instanceof Class && ((Class) this.type).isEnum()) {
    this.isEnum = true;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:FieldAttributeModel.java

示例4: registerTypeAdapter

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
/**
 * Configures Gson for custom serialization or deserialization. This method combines the
 * registration of an {@link InstanceCreator}, {@link JsonSerializer}, and a
 * {@link JsonDeserializer}. It is best used when a single object {@code typeAdapter} implements
 * all the required interfaces for custom serialization with Gson. If an instance creator,
 * serializer or deserializer was previously registered for the specified {@code type}, it is
 * overwritten.
 *
 * @param type the type definition for the type adapter being registered
 * @param typeAdapter This object must implement at least one of the {@link InstanceCreator},
 * {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.
 * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
  $Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
      || typeAdapter instanceof JsonDeserializer<?>
      || typeAdapter instanceof InstanceCreator<?>
      || typeAdapter instanceof TypeAdapter<?>);
  if (Primitives.isPrimitive(type) || Primitives.isWrapperType(type)) {
    throw new IllegalArgumentException(
        "Cannot register type adapters for " + type);
  }
  if (typeAdapter instanceof InstanceCreator<?>) {
    instanceCreators.put(type, (InstanceCreator) typeAdapter);
  }
  if (typeAdapter instanceof JsonSerializer<?> || typeAdapter instanceof JsonDeserializer<?>) {
    TypeToken<?> typeToken = TypeToken.get(type);
    factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(typeToken, typeAdapter));
  }
  if (typeAdapter instanceof TypeAdapter<?>) {
    factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter)typeAdapter));
  }
  return this;
}
 
开发者ID:appcelerator-archive,项目名称:ti.box,代码行数:36,代码来源:GsonBuilder.java

示例5: registerTypeAdapter

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
/**
 * Configures Gson for custom serialization or deserialization. This method combines the
 * registration of an {@link TypeAdapter}, {@link InstanceCreator}, {@link JsonSerializer}, and a
 * {@link JsonDeserializer}. It is best used when a single object {@code typeAdapter} implements
 * all the required interfaces for custom serialization with Gson. If a type adapter was
 * previously registered for the specified {@code type}, it is overwritten.
 *
 * @param type the type definition for the type adapter being registered
 * @param typeAdapter This object must implement at least one of the {@link TypeAdapter},
 * {@link InstanceCreator}, {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.
 * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
  $Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
      || typeAdapter instanceof JsonDeserializer<?>
      || typeAdapter instanceof InstanceCreator<?>
      || typeAdapter instanceof TypeAdapter<?>);
  if (Primitives.isPrimitive(type) || Primitives.isWrapperType(type)) {
    throw new IllegalArgumentException(
        "Cannot register type adapters for " + type);
  }
  if (typeAdapter instanceof InstanceCreator<?>) {
    instanceCreators.put(type, (InstanceCreator) typeAdapter);
  }
  if (typeAdapter instanceof JsonSerializer<?> || typeAdapter instanceof JsonDeserializer<?>) {
    TypeToken<?> typeToken = TypeToken.get(type);
    factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(typeToken, typeAdapter));
  }
  if (typeAdapter instanceof TypeAdapter<?>) {
    factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter)typeAdapter));
  }
  return this;
}
 
开发者ID:jingshauizh,项目名称:androidsummary,代码行数:35,代码来源:GsonBuilder.java

示例6: deserialize

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public MyParameterizedType<T> deserialize(JsonElement json, Type typeOfT,
    JsonDeserializationContext context) throws JsonParseException {
  Type genericClass = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
  Class<?> rawType = $Gson$Types.getRawType(genericClass);
  String className = rawType.getSimpleName();
  JsonElement jsonElement = json.getAsJsonObject().get(className);

  T value;
  if (genericClass == Integer.class) {
    value = (T) Integer.valueOf(jsonElement.getAsInt());
  } else if (genericClass == String.class) {
    value = (T) jsonElement.getAsString();
  } else {
    value = (T) jsonElement;
  }

  if (Primitives.isPrimitive(genericClass)) {
    PrimitiveTypeAdapter typeAdapter = new PrimitiveTypeAdapter();
    value = (T) typeAdapter.adaptType(value, rawType);
  }
  return new MyParameterizedType<T>(value);
}
 
开发者ID:vparfonov,项目名称:gson,代码行数:24,代码来源:ParameterizedTypeFixtures.java

示例7: read

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public T read() throws JsonSyntaxException, JsonIOException {
    if (Primitives.isPrimitive(valueType)) {
        Object parsed = mapper.fromJson(source, valueType);
        return (T) Primitives.wrap(parsed.getClass()).cast(parsed);
    }
    else {
        return mapper.fromJson(source, valueType);
    }
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:12,代码来源:JsonSourceReader.java

示例8: read

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public T read(Reader source) throws JsonSyntaxException, JsonIOException {
    requireNonNull(source, "source");

    if (Primitives.isPrimitive(valueType)) {
        Object parsed = mapper.fromJson(source, valueType);
        return (T) Primitives.wrap(parsed.getClass()).cast(parsed);
    }
    else {
        return mapper.fromJson(source, valueType);
    }
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:14,代码来源:JsonSourceReader.java

示例9: a

import com.google.gson.internal.Primitives; //导入方法依赖的package包/类
private j a(Gson gson, Field field, String s, TypeToken typetoken, boolean flag, boolean flag1)
{
    return new i(this, s, flag, flag1, gson, typetoken, field, Primitives.isPrimitive(typetoken.getRawType()));
}
 
开发者ID:vishnudevk,项目名称:MiBandDecompiled,代码行数:5,代码来源:ReflectiveTypeAdapterFactory.java


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