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


Java GsonBuilder.serializeNulls方法代码示例

本文整理汇总了Java中com.google.gson.GsonBuilder.serializeNulls方法的典型用法代码示例。如果您正苦于以下问题:Java GsonBuilder.serializeNulls方法的具体用法?Java GsonBuilder.serializeNulls怎么用?Java GsonBuilder.serializeNulls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.GsonBuilder的用法示例。


在下文中一共展示了GsonBuilder.serializeNulls方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGson

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private Gson getGson() {
    if (gson == null) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setFieldNamingStrategy(new AnnotateNaming());
        gsonBuilder.serializeNulls();
        gsonBuilder.excludeFieldsWithModifiers(Modifier.TRANSIENT);
        gson = gsonBuilder.create();
    }
    return gson;
}
 
开发者ID:zhao-mingjian,项目名称:qvod,代码行数:11,代码来源:HttpUtils.java

示例2: buildGson

import com.google.gson.GsonBuilder; //导入方法依赖的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: getGson

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private Gson getGson() {
    if (gson == null) {
        GsonBuilder builder = new GsonBuilder();
        builder.setLenient();
        builder.setFieldNamingStrategy(new AnnotateNaming());
        builder.serializeNulls();
        gson = builder.create();
    }
    return gson;
}
 
开发者ID:joelan,项目名称:ClouldReader,代码行数:11,代码来源:HttpUtils.java

示例4: createGson

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
     * Create the standard {@link Gson} configuration
     *
     * @param serializeNulls whether nulls should be serialized
     * @return created gson, never null
     */
    public static final Gson createGson(final boolean serializeNulls) {
        final GsonBuilder builder = new GsonBuilder();
//		builder.registerTypeAdapter(Date.class, new DateFormatter());
//		builder.registerTypeAdapter(Event.class, new EventFormatter());
        builder.setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES);
        if (serializeNulls)
            builder.serializeNulls();
        return builder.create();
    }
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:GsonUtils.java

示例5: create

import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static final Gson create(boolean pretty) {
	GsonBuilder builder = new GsonBuilder();
	builder.serializeNulls();
	builder.disableHtmlEscaping();

	// Install MongoDB / BSON serializers
	tryToAddSerializers("io.datatree.dom.adapters.JsonGsonBsonSerializers", builder);

	// Install serializers for Apache Cassandra
	addSerializer(builder, InetAddress.class, (value) -> {
		return new JsonPrimitive(value.getCanonicalHostName());
	});
	addSerializer(builder, Inet4Address.class, (value) -> {
		return new JsonPrimitive(value.getCanonicalHostName());
	});
	addSerializer(builder, Inet6Address.class, (value) -> {
		return new JsonPrimitive(value.getCanonicalHostName());
	});

	// Date serializer
	if (Config.USE_TIMESTAMPS) {
		builder.setDateFormat(Config.TIMESTAMP_FORMAT);
	} else {

		// Milliseconds since epoch Jan 1 , 1970 00:00:00 UTC
		addSerializer(builder, Date.class, (value) -> {
			return new JsonPrimitive(value.getTime());
		});
	}

	// BASE64 serializer
	addSerializer(builder, byte[].class, (value) -> {
		return new JsonPrimitive(BASE64.encode(value));
	});

	// Pretty printing
	if (pretty) {
		builder.setPrettyPrinting();
	}
	return builder.create();
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:42,代码来源:JsonGson.java


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