Package com.google.gson

Examples of com.google.gson.TypeAdapter


                        writer.setSerializeNulls(true);
                        oldSerializeNulls = Boolean.FALSE;
                    }
                }

                TypeAdapter t = new TypeAdapterRuntimeTypeWrapper(context, this.typeAdapter, fieldType.getType());
                t.write(writer, fieldValue);

                if (oldSerializeNulls != null) {
                    writer.setSerializeNulls(oldSerializeNulls.booleanValue());
                }
            }
View Full Code Here


      final TypeAdapter<?> typeAdapter = context.getAdapter(fieldType);
      @SuppressWarnings({"unchecked", "rawtypes"}) // the type adapter and field type always agree
      @Override void write(JsonWriter writer, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = field.get(value);
        TypeAdapter t =
          new TypeAdapterRuntimeTypeWrapper(context, this.typeAdapter, fieldType.getType());
        t.write(writer, fieldValue);
      }
      @Override void read(JsonReader reader, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = this.typeAdapter.read(reader);
        if (fieldValue != null || !isPrimitive) {
View Full Code Here

            jsonWriter.name(name);
            if (type instanceof TypeVariable || type == Object.class) {
              // We can not use Gson to extract the value, so just use the specified value.
              jsonWriter.value((String)value);
            } else {
              TypeAdapter adapter = gson.getAdapter(TypeToken.get(type));
              adapter.write(jsonWriter, value);
            }
          }
        };
        for (Field f : navigator.getFields()) {
          extractUrlParam(f.getName(), f.getGenericType(), requestParams, receiver);
View Full Code Here

      final TypeAdapter<?> typeAdapter = getFieldAdapter(context, field, fieldType);
      @SuppressWarnings({"unchecked", "rawtypes"}) // the type adapter and field type always agree
      @Override void write(JsonWriter writer, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = field.get(value);
        TypeAdapter t =
          new TypeAdapterRuntimeTypeWrapper(context, this.typeAdapter, fieldType.getType());
        t.write(writer, fieldValue);
      }
      @Override void read(JsonReader reader, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = typeAdapter.read(reader);
        if (fieldValue != null || !isPrimitive) {
View Full Code Here

      final TypeAdapter<?> typeAdapter = context.getAdapter(fieldType);
      @SuppressWarnings({"unchecked", "rawtypes"}) // the type adapter and field type always agree
      @Override void write(JsonWriter writer, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = field.get(value);
        TypeAdapter t =
          new TypeAdapterRuntimeTypeWrapper(context, this.typeAdapter, fieldType.getType());
        t.write(writer, fieldValue);
      }
      @Override void read(JsonReader reader, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = typeAdapter.read(reader);
        if (fieldValue != null || !isPrimitive) {
View Full Code Here

      final TypeAdapter<?> typeAdapter = getFieldAdapter(context, field, fieldType);
      @SuppressWarnings({"unchecked", "rawtypes"}) // the type adapter and field type always agree
      @Override void write(JsonWriter writer, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = field.get(value);
        TypeAdapter t =
          new TypeAdapterRuntimeTypeWrapper(context, this.typeAdapter, fieldType.getType());
        t.write(writer, fieldValue);
      }
      @Override void read(JsonReader reader, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = typeAdapter.read(reader);
        if (fieldValue != null || !isPrimitive) {
View Full Code Here

    // First preference: a type adapter registered for the runtime type
    // Second preference: a type adapter registered for the declared type
    // Third preference: reflective type adapter for the runtime type (if it is a sub class of the declared type)
    // Fourth preference: reflective type adapter for the declared type

    TypeAdapter chosen = delegate;
    Type runtimeType = getRuntimeTypeIfMoreSpecific(type, value);
    if (runtimeType != type) {
      TypeAdapter runtimeTypeAdapter = context.getAdapter(TypeToken.get(runtimeType));
      if (!(runtimeTypeAdapter instanceof ReflectiveTypeAdapterFactory.Adapter)) {
        // The user registered a type adapter for the runtime type, so we will use that
        chosen = runtimeTypeAdapter;
      } else if (!(delegate instanceof ReflectiveTypeAdapterFactory.Adapter)) {
        // The user registered a type adapter for Base class, so we prefer it over the
View Full Code Here

      final TypeAdapter<?> typeAdapter = getFieldAdapter(context, field, fieldType);
      @SuppressWarnings({"unchecked", "rawtypes"}) // the type adapter and field type always agree
      @Override void write(JsonWriter writer, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = field.get(value);
        TypeAdapter t =
          new TypeAdapterRuntimeTypeWrapper(context, this.typeAdapter, fieldType.getType());
        t.write(writer, fieldValue);
      }
      @Override void read(JsonReader reader, Object value)
          throws IOException, IllegalAccessException {
        Object fieldValue = typeAdapter.read(reader);
        if (fieldValue != null || !isPrimitive) {
View Full Code Here

  @SuppressWarnings({ "rawtypes", "unchecked" })
  public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> targetType) {
    Class<? super T> clazz = targetType.getRawType();
    JsonAdapter annotation = clazz.getAnnotation(JsonAdapter.class);
    if (annotation == null) return null;
    TypeAdapter adapter = getAnnotationTypeAdapter(gson, constructorConstructor, annotation);
    return adapter;
  }
View Full Code Here

    Class localClass1 = paramTypeToken.getRawType();
    if (!Map.class.isAssignableFrom(localClass1))
      return null;
    Class localClass2 = $Gson.Types.getRawType(localType);
    Type[] arrayOfType = $Gson.Types.getMapKeyAndValueTypes(localType, localClass2);
    TypeAdapter localTypeAdapter1 = getKeyAdapter(paramGson, arrayOfType[0]);
    TypeAdapter localTypeAdapter2 = paramGson.getAdapter(TypeToken.get(arrayOfType[1]));
    ObjectConstructor localObjectConstructor = this.constructorConstructor.get(paramTypeToken);
    Adapter localAdapter = new Adapter(paramGson, arrayOfType[0], localTypeAdapter1, arrayOfType[1], localTypeAdapter2, localObjectConstructor);
    return localAdapter;
  }
View Full Code Here

TOP

Related Classes of com.google.gson.TypeAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.