Package com.google.gson

Examples of com.google.gson.TypeAdapterFactory


    };
  }

  public static <TT> TypeAdapterFactory newFactory(
      final Class<TT> unboxed, final Class<TT> boxed, final TypeAdapter<? super TT> typeAdapter) {
    return new TypeAdapterFactory() {
      @SuppressWarnings("unchecked") // we use a runtime check to make sure the 'T's equal
      public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
        Class<? super T> rawType = typeToken.getRawType();
        return (rawType == unboxed || rawType == boxed) ? (TypeAdapter<T>) typeAdapter : null;
      }
View Full Code Here


    };
  }

  public static <TT> TypeAdapterFactory newFactoryForMultipleTypes(final Class<TT> base,
      final Class<? extends TT> sub, final TypeAdapter<? super TT> typeAdapter) {
    return new TypeAdapterFactory() {
      @SuppressWarnings("unchecked") // we use a runtime check to make sure the 'T's equal
      public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
        Class<? super T> rawType = typeToken.getRawType();
        return (rawType == base || rawType == sub) ? (TypeAdapter<T>) typeAdapter : null;
      }
View Full Code Here

    };
  }

  public static <TT> TypeAdapterFactory newTypeHierarchyFactory(
      final Class<TT> clazz, final TypeAdapter<TT> typeAdapter) {
    return new TypeAdapterFactory() {
      @SuppressWarnings("unchecked")
      public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
        return clazz.isAssignableFrom(typeToken.getRawType()) ? (TypeAdapter<T>) typeAdapter : null;
      }
      @Override public String toString() {
View Full Code Here

  public static final TypeAdapterFactory JSON_ELEMENT_FACTORY = newFactory(JsonElement.class, JSON_ELEMENT);
  public static final TypeAdapterFactory ENUM_FACTORY = newEnumTypeHierarchyFactory();

  public static TypeAdapterFactory newEnumTypeHierarchyFactory()
  {
    return new TypeAdapterFactory()
    {
      public TypeAdapter create(Gson paramAnonymousGson, TypeToken paramAnonymousTypeToken)
      {
        Class localClass = paramAnonymousTypeToken.getRawType();
        if ((!Enum.class.isAssignableFrom(localClass)) || (localClass == Enum.class))
View Full Code Here

    };
  }

  public static TypeAdapterFactory newFactory(TypeToken paramTypeToken, final TypeAdapter paramTypeAdapter)
  {
    return new TypeAdapterFactory()
    {
      public TypeAdapter create(Gson paramAnonymousGson, TypeToken paramAnonymousTypeToken)
      {
        return paramAnonymousTypeToken.equals(this.val$type) ? paramTypeAdapter : null;
      }
View Full Code Here

    };
  }

  public static TypeAdapterFactory newFactory(Class paramClass, final TypeAdapter paramTypeAdapter)
  {
    return new TypeAdapterFactory()
    {
      public TypeAdapter create(Gson paramAnonymousGson, TypeToken paramAnonymousTypeToken)
      {
        return paramAnonymousTypeToken.getRawType() == this.val$type ? paramTypeAdapter : null;
      }
View Full Code Here

    };
  }

  public static TypeAdapterFactory newFactory(Class paramClass1, final Class paramClass2, final TypeAdapter paramTypeAdapter)
  {
    return new TypeAdapterFactory()
    {
      public TypeAdapter create(Gson paramAnonymousGson, TypeToken paramAnonymousTypeToken)
      {
        Class localClass = paramAnonymousTypeToken.getRawType();
        return (localClass == this.val$unboxed) || (localClass == paramClass2) ? paramTypeAdapter : null;
View Full Code Here

    };
  }

  public static TypeAdapterFactory newFactoryForMultipleTypes(Class paramClass1, final Class paramClass2, final TypeAdapter paramTypeAdapter)
  {
    return new TypeAdapterFactory()
    {
      public TypeAdapter create(Gson paramAnonymousGson, TypeToken paramAnonymousTypeToken)
      {
        Class localClass = paramAnonymousTypeToken.getRawType();
        return (localClass == this.val$base) || (localClass == paramClass2) ? paramTypeAdapter : null;
View Full Code Here

    };
  }

  public static TypeAdapterFactory newTypeHierarchyFactory(Class paramClass, final TypeAdapter paramTypeAdapter)
  {
    return new TypeAdapterFactory()
    {
      public TypeAdapter create(Gson paramAnonymousGson, TypeToken paramAnonymousTypeToken)
      {
        return this.val$clazz.isAssignableFrom(paramAnonymousTypeToken.getRawType()) ? paramTypeAdapter : null;
      }
View Full Code Here

TOP

Related Classes of com.google.gson.TypeAdapterFactory

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.