当前位置: 首页>>代码示例>>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;未经允许,请勿转载。