當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeAdapterFactory類代碼示例

本文整理匯總了Java中com.google.gson.TypeAdapterFactory的典型用法代碼示例。如果您正苦於以下問題:Java TypeAdapterFactory類的具體用法?Java TypeAdapterFactory怎麽用?Java TypeAdapterFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeAdapterFactory類屬於com.google.gson包,在下文中一共展示了TypeAdapterFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTypeAdapter

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
@SuppressWarnings("unchecked") // Casts guarded by conditionals.
static TypeAdapter<?> getTypeAdapter(ConstructorConstructor constructorConstructor, Gson gson,
    TypeToken<?> fieldType, JsonAdapter annotation) {
  Class<?> value = annotation.value();
  if (TypeAdapter.class.isAssignableFrom(value)) {
        Class<TypeAdapter<?>> typeAdapter = (Class<TypeAdapter<?>>) value;
    return constructorConstructor.get(TypeToken.get(typeAdapter)).construct();
  }
  if (TypeAdapterFactory.class.isAssignableFrom(value)) {
        Class<TypeAdapterFactory> typeAdapterFactory = (Class<TypeAdapterFactory>) value;
    return constructorConstructor.get(TypeToken.get(typeAdapterFactory))
        .construct()
        .create(gson, fieldType);
  }

  throw new IllegalArgumentException(
      "@JsonAdapter value must be TypeAdapter or TypeAdapterFactory reference.");
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:19,代碼來源:JsonAdapterAnnotationTypeAdapterFactory.java

示例2: buildGson

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
public static Gson buildGson() {

        final GsonBuilder gson = new GsonBuilder();

        //gson.setPrettyPrinting();
        gson.serializeNulls();
        gson.excludeFieldsWithModifiers(Modifier.STATIC, Modifier.TRANSIENT, Modifier.VOLATILE);

        // register the type adapter factories
        final TypeAdapterFactoryCreator creator = new TypeAdapterFactoryCreator();
        for (final TypeAdapterFactory factory : creator.getAdapters()) {
            gson.registerTypeAdapterFactory(factory);
        }

        return gson.create();
    }
 
開發者ID:MikeFot,項目名稱:Java--Steam-Loader,代碼行數:17,代碼來源:SteamGson.java

示例3: getTypeAdapter

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
@SuppressWarnings("unchecked") // Casts guarded by conditionals.
static TypeAdapter<?> getTypeAdapter(ConstructorConstructor constructorConstructor, Gson gson,
    TypeToken<?> fieldType, JsonAdapter annotation) {
  Class<?> value = annotation.value();
  TypeAdapter<?> typeAdapter;
  if (TypeAdapter.class.isAssignableFrom(value)) {
    Class<TypeAdapter<?>> typeAdapterClass = (Class<TypeAdapter<?>>) value;
    typeAdapter = constructorConstructor.get(TypeToken.get(typeAdapterClass)).construct();
  } else if (TypeAdapterFactory.class.isAssignableFrom(value)) {
    Class<TypeAdapterFactory> typeAdapterFactory = (Class<TypeAdapterFactory>) value;
    typeAdapter = constructorConstructor.get(TypeToken.get(typeAdapterFactory))
        .construct()
        .create(gson, fieldType);
  } else {
    throw new IllegalArgumentException(
        "@JsonAdapter value must be TypeAdapter or TypeAdapterFactory reference.");
  }
  if (typeAdapter != null) {
    typeAdapter = typeAdapter.nullSafe();
  }
  return typeAdapter;
}
 
開發者ID:MyJojoX,項目名稱:MyJojoXUtils,代碼行數:23,代碼來源:JsonAdapterAnnotationTypeAdapterFactory.java

示例4: generateBuilder

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
protected static GsonBuilder generateBuilder() {
	GsonBuilder builder = new GsonBuilder();
	
	synchronized (typeAdapters) {
		for (Entry<Class<?>, Object> adapter : typeAdapters.entrySet()) {
			builder.registerTypeAdapter(adapter.getKey(), adapter.getValue());
		}
	}
	synchronized (typeAdapterFactories) {
		for (TypeAdapterFactory factory : typeAdapterFactories) {
			builder.registerTypeAdapterFactory(factory);
		}
	}
	
	return builder;
}
 
開發者ID:MyJojoX,項目名稱:MyJojoXUtils,代碼行數:17,代碼來源:JSONUtils.java

示例5: newFactory

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
public static <TT> TypeAdapterFactory newFactory(Class<TT> paramClass, final TypeAdapter<TT> paramTypeAdapter)
{
  new TypeAdapterFactory()
  {
    public final <T> TypeAdapter<T> create(Gson paramAnonymousGson, TypeToken<T> paramAnonymousTypeToken)
    {
      if (paramAnonymousTypeToken.rawType == this.val$type) {
        return paramTypeAdapter;
      }
      return null;
    }
    
    public final String toString()
    {
      return "Factory[type=" + this.val$type.getName() + ",adapter=" + paramTypeAdapter + "]";
    }
  };
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:19,代碼來源:TypeAdapters.java

示例6: DefaultRuntimeTypeAdapterFactory

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
/**
 * @param context
 * @param baseClass  
 * @param defaultClass  Setting this to null will cause a ParseException if the runtime type information is incorrect or unavailable.
 */
public DefaultRuntimeTypeAdapterFactory(Context context, Class<E> baseClass, Class<? extends E> defaultClass, TypeAdapterFactory delegateFactory) {
	assert context != null && baseClass != null;
	if (defaultClass != null && !isInstantiable(defaultClass)) {
		throw new RuntimeException("Default class does not have a default contructor.");
	}
	this.context = context;
	this.baseClass = baseClass;
	this.defaultClass = defaultClass;
	if (delegateFactory == null) {
		this.delegateFactory = new ReflectiveTypeAdapterFactory(
				new ConstructorConstructor(Collections.<Type, InstanceCreator<?>>emptyMap()), 
				FieldNamingPolicy.IDENTITY, 
				Excluder.DEFAULT);
	} else {
		this.delegateFactory = delegateFactory;
	}
}
 
開發者ID:OpenSensing,項目名稱:funf-v4,代碼行數:23,代碼來源:DefaultRuntimeTypeAdapterFactory.java

示例7: createGson

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
private static Gson createGson() {
  GsonBuilder gsonBuilder = new GsonBuilder();
  for (TypeAdapterFactory factory : ServiceLoader.load(TypeAdapterFactory.class)) {
    gsonBuilder.registerTypeAdapterFactory(factory);
  }
  return gsonBuilder.create();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:RepositorySetup.java

示例8: gson

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
/**
 * the fully configured gson instance.
 * @return the gson instanse
 */
@Value.Default
public Gson gson() {
  GsonBuilder gsonBuilder = new GsonBuilder();
  for (TypeAdapterFactory factory : ServiceLoader.load(TypeAdapterFactory.class)) {
    gsonBuilder.registerTypeAdapterFactory(factory);
  }
  return gsonBuilder.create();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:GsonMessageBodyProvider.java

示例9: gsonBuilder

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
@Provides
GsonBuilder gsonBuilder(Set<TypeAdapterFactory> factories, Map<Type, Object> adapters, Map<Class, Object> hiearchyAdapters) {
    GsonBuilder builder = new GsonBuilder()
        .setDateFormat(ISO8601_DATE_FORMAT)
        .serializeSpecialFloatingPointValues() // Infinity and NaN
        .serializeNulls(); // Needed so we can clear fields in PartialModel document updates

    factories.forEach(builder::registerTypeAdapterFactory);
    adapters.forEach(builder::registerTypeAdapter);
    hiearchyAdapters.forEach(builder::registerTypeHierarchyAdapter);

    return builder;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:14,代碼來源:SerializationManifest.java

示例10: newEnumTypeHierarchyFactory

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
public static <TT> TypeAdapterFactory newEnumTypeHierarchyFactory() {
    return new TypeAdapterFactory() {
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
            Class<? super T> rawType = typeToken.getRawType();
            if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) {
                return null;
            }
            if (!rawType.isEnum()) {
                rawType = rawType.getSuperclass();
            }
            return new EnumTypeAdapter(rawType);
        }
    };
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:15,代碼來源:TypeAdapters.java

示例11: newFactory

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
public static <TT> TypeAdapterFactory newFactory(final TypeToken<TT> type, final TypeAdapter<TT> typeAdapter) {
    return new TypeAdapterFactory() {
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
            return typeToken.equals(type) ? typeAdapter : null;
        }
    };
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:8,代碼來源:TypeAdapters.java

示例12: newFactoryForMultipleTypes

import com.google.gson.TypeAdapterFactory; //導入依賴的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

示例13: newTypeHierarchyFactory

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
public static <TT> TypeAdapterFactory newTypeHierarchyFactory(final Class<TT> clazz, final TypeAdapter<TT> typeAdapter) {
    return new TypeAdapterFactory() {
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
            return clazz.isAssignableFrom(typeToken.getRawType()) ? typeAdapter : null;
        }

        public String toString() {
            return "Factory[typeHierarchy=" + clazz.getName() + ",adapter=" + typeAdapter + "]";
        }
    };
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:12,代碼來源:TypeAdapters.java

示例14: newFactory

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
public static <TT> TypeAdapterFactory newFactory(
    final TypeToken<TT> type, final TypeAdapter<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) {
      return typeToken.equals(type) ? (TypeAdapter<T>) typeAdapter : null;
    }
  };
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:10,代碼來源:TypeAdapters.java

示例15: newFactoryForMultipleTypes

import com.google.gson.TypeAdapterFactory; //導入依賴的package包/類
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;
    }
    @Override public String toString() {
      return "Factory[type=" + base.getName()
          + "+" + sub.getName() + ",adapter=" + typeAdapter + "]";
    }
  };
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:15,代碼來源:TypeAdapters.java


注:本文中的com.google.gson.TypeAdapterFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。