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


Java TypeAdapters类代码示例

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


TypeAdapters类属于com.google.gson.internal.bind包,在下文中一共展示了TypeAdapters类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: floatAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
    if (serializeSpecialFloatingPointValues) {
        return TypeAdapters.FLOAT;
    }
    return new TypeAdapter<Number>() {
        public Float read(JsonReader in) throws IOException {
            if (in.peek() != JsonToken.NULL) {
                return Float.valueOf((float) in.nextDouble());
            }
            in.nextNull();
            return null;
        }

        public void write(JsonWriter out, Number value) throws IOException {
            if (value == null) {
                out.nullValue();
                return;
            }
            Gson.this.checkValidFloatingPoint((double) value.floatValue());
            out.value(value);
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:Gson.java

示例2: doubleAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) {
    if (serializeSpecialFloatingPointValues) {
        return TypeAdapters.DOUBLE;
    }
    return new TypeAdapter<Number>() {
        public Double read(JsonReader in) throws IOException {
            if (in.peek() != JsonToken.NULL) {
                return Double.valueOf(in.nextDouble());
            }
            in.nextNull();
            return null;
        }

        public void write(JsonWriter out, Number value) throws IOException {
            if (value == null) {
                out.nullValue();
                return;
            }
            Gson.this.checkValidFloatingPoint(value.doubleValue());
            out.value(value);
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:Gson.java

示例3: longAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
private TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) {
    if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) {
        return TypeAdapters.LONG;
    }
    return new TypeAdapter<Number>() {
        public Number read(JsonReader in) throws IOException {
            if (in.peek() != JsonToken.NULL) {
                return Long.valueOf(in.nextLong());
            }
            in.nextNull();
            return null;
        }

        public void write(JsonWriter out, Number value) throws IOException {
            if (value == null) {
                out.nullValue();
            } else {
                out.value(value.toString());
            }
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:23,代码来源:Gson.java

示例4: registerTypeAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的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

示例5: registerTypeHierarchyAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
    boolean z;
    if ((typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof TypeAdapter)) {
        z = true;
    } else {
        z = false;
    }
    C$Gson$Preconditions.checkArgument(z);
    if ((typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof JsonSerializer)) {
        this.hierarchyFactories.add(0, TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter));
    }
    if (typeAdapter instanceof TypeAdapter) {
        this.factories.add(TypeAdapters.newTypeHierarchyFactory(baseType, (TypeAdapter) typeAdapter));
    }
    return this;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:GsonBuilder.java

示例6: parse

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonIOException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:Streams.java

示例7: doubleAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) {
  if (serializeSpecialFloatingPointValues) {
    return TypeAdapters.DOUBLE;
  }
  return new TypeAdapter<Number>() {
    @Override public Double read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return in.nextDouble();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      double doubleValue = value.doubleValue();
      checkValidFloatingPoint(doubleValue);
      out.value(value);
    }
  };
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:24,代码来源:Gson.java

示例8: floatAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
  if (serializeSpecialFloatingPointValues) {
    return TypeAdapters.FLOAT;
  }
  return new TypeAdapter<Number>() {
    @Override public Float read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return (float) in.nextDouble();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      float floatValue = value.floatValue();
      checkValidFloatingPoint(floatValue);
      out.value(value);
    }
  };
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:24,代码来源:Gson.java

示例9: longAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
private TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) {
  if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) {
    return TypeAdapters.LONG;
  }
  return new TypeAdapter<Number>() {
    @Override public Number read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return in.nextLong();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      out.value(value.toString());
    }
  };
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:22,代码来源:Gson.java

示例10: registerTypeAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的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.
 *
 * <p>This registers the type specified and no other types: you must manually register related
 * types! For example, applications registering {@code boolean.class} should also register {@code
 * Boolean.class}.
 *
 * @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 (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:odoo-mobile-intern,项目名称:odoo-work,代码行数:35,代码来源:GsonBuilder.java

示例11: registerTypeAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的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 (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,项目名称:boohee_v5.6,代码行数:19,代码来源:GsonBuilder.java

示例12: registerTypeHierarchyAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) {
    boolean z;
    if ((typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer)
            || (typeAdapter instanceof TypeAdapter)) {
        z = true;
    } else {
        z = false;
    }
    C$Gson$Preconditions.checkArgument(z);
    if ((typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof JsonSerializer)) {
        this.hierarchyFactories.add(0, TreeTypeAdapter.newTypeHierarchyFactory(baseType,
                typeAdapter));
    }
    if (typeAdapter instanceof TypeAdapter) {
        this.factories.add(TypeAdapters.newTypeHierarchyFactory(baseType, (TypeAdapter)
                typeAdapter));
    }
    return this;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:GsonBuilder.java

示例13: parse

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonSyntaxException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:Streams.java

示例14: longAdapter

import com.google.gson.internal.bind.TypeAdapters; //导入依赖的package包/类
private static TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) {
  if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) {
    return TypeAdapters.LONG;
  }
  return new TypeAdapter<Number>() {
    @Override public Number read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return in.nextLong();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      out.value(value.toString());
    }
  };
}
 
开发者ID:MyJojoX,项目名称:MyJojoXUtils,代码行数:22,代码来源:Gson.java


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