本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}