本文整理汇总了Java中com.google.gson.GsonBuilder.setPrettyPrinting方法的典型用法代码示例。如果您正苦于以下问题:Java GsonBuilder.setPrettyPrinting方法的具体用法?Java GsonBuilder.setPrettyPrinting怎么用?Java GsonBuilder.setPrettyPrinting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.GsonBuilder
的用法示例。
在下文中一共展示了GsonBuilder.setPrettyPrinting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGsonBuilder
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* 构建通用GsonBuilder, 封装初始化工作
*
* @return
*/
public static GsonBuilder getGsonBuilder(boolean prettyPrinting) {
GsonBuilder gb = new GsonBuilder();
gb.setDateFormat("yyyy-MM-dd HH:mm:ss:mss");
gb.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getAnnotation(WJsonExclued.class) != null;
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return clazz.getAnnotation(WJsonExclued.class) != null;
}
});
if (prettyPrinting)
gb.setPrettyPrinting();
return gb;
}
示例2: getGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* Generates a gson that has all of the common features loaded in.
* @return a gson object
*/
private static Gson getGson() {
if (sGson == null) {
GsonBuilder builder = new GsonBuilder();
RuntimeTypeAdapterFactory<BaseClass> adapter = RuntimeTypeAdapterFactory
.of(BaseClass.class)
.registerSubtype(Amazon.class)
.registerSubtype(Barbarian.class)
.registerSubtype(Centaur.class)
.registerSubtype(Elementalist.class)
.registerSubtype(Hunter.class)
.registerSubtype(Lyrist.class)
.registerSubtype(Magician.class)
.registerSubtype(Noble.class)
.registerSubtype(Nymph.class)
.registerSubtype(Priest.class)
.registerSubtype(Sorcerer.class)
.registerSubtype(Spearman.class)
.registerSubtype(Thief.class);
builder.registerTypeAdapter(PlayerCharacter.class, new CharacterSerializer());
builder.registerTypeAdapterFactory(adapter);
builder.setPrettyPrinting();
sGson = builder.create();
}
return sGson;
}
示例3: ParameterBuilder
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public ParameterBuilder(String language) {
gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
this.parameter = new Parameter();
this.parameter.setLanguage(language);
this.parameter.setSettings(defaultSettings());
}
示例4: configureGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private static void configureGson() {
// Configure GSON
final GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Date.class, new CustomDateSerializer());
gsonBuilder.registerTypeAdapter(Post.class, new PostDeserializer());
gsonBuilder.setPrettyPrinting();
gson = gsonBuilder.create();
}
示例5: getGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static Gson getGson() {
GsonBuilder bson = new GsonBuilder();
bson.registerTypeAdapter(IntRange.class, new IntRangeAdapter());
bson.registerTypeAdapter(ContextCondition.class, new ContextConditionAdapter());
bson.registerTypeAdapter(Station.class, new StationAdapter());
bson.registerTypeAdapter(Formula.class, new FormulaAdapter());
bson.registerTypeAdapter(Conjunction.class, new ConjunctionAdapter());
bson.registerTypeAdapter(SongCollection.class, new SongCollectionAdapter());
bson.setPrettyPrinting();
return bson.create();
}
示例6: generateJson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private static String generateJson(GameDefinition gameDefinition) {
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
String result = gson.toJson(gameDefinition);
return result;
}
示例7: createSettings
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private void createSettings() {
File out = new File(System.getProperty("user.dir"), "settings.json");
try (Writer writer = new FileWriter(out)) {
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
SettingsWrapper wrapper = new SettingsWrapper();
wrapper.setGui(FatesGui.getInstance());
wrapper.setCharacters(characters.getWorkingCharacters());
gson.toJson(wrapper, writer);
} catch(IOException ex) {
ex.printStackTrace();
}
}
示例8: getGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static Gson getGson(boolean prettyPrint)
{
GsonBuilder gb = new GsonBuilder()
.registerTypeAdapter(DateTime.class, new MyDateTimeAdapter());
if (prettyPrint)
gb = gb.setPrettyPrinting();
return gb.create();
}
示例9: json
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private String json()
{
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
builder.disableHtmlEscaping();
Gson gson = builder.create();
return gson.toJson(this);
}
示例10: DocumentRepository
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
protected DocumentRepository() {
GsonBuilder builder = new GsonBuilder();
DocumentTypeAdapter documentAdapter = new DocumentTypeAdapter();
builder.registerTypeAdapter(Document.class, documentAdapter);
builder.setPrettyPrinting();
gson = builder.create();
}
示例11: toJson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public String toJson(Object object){
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Date.class, new AdapterDate());
builder.setExclusionStrategies(new TestExclStrat());
builder.setPrettyPrinting();
Gson gson = builder.create();
return gson.toJson(object);
}
示例12: getGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private static Gson getGson() {
if (sGson == null) {
GsonBuilder builder = new GsonBuilder();
RuntimeTypeAdapterFactory adapter = RuntimeTypeAdapterFactory
.of(Equipment.class)
.registerSubtype(Equipment.class)
.registerSubtype(Weapon.class)
.registerSubtype(Armor.class)
.registerSubtype(Mythics.class);
builder.registerTypeAdapterFactory(adapter);
builder.setPrettyPrinting();
sGson = builder.create();
}
return sGson;
}
示例13: getGsonWithoutExposed
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
@Provides
@Named("IgnoreExposedBS")
@Nonnull
public Gson getGsonWithoutExposed(@Nonnull Injector injector) {
GsonBuilder builder = new GsonBuilder();
addTypeAdapters(builder, injector);
builder.setPrettyPrinting();
return builder.create();
}
示例14: 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();
}
示例15: toJson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public static String toJson(Object object) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
return gson.toJson(object);
}