當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。