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


Java GsonBuilder.setPrettyPrinting方法代码示例

本文整理汇总了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;
}
 
开发者ID:DataAgg,项目名称:DaUtil,代码行数:24,代码来源:WJsonUtils.java

示例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;
}
 
开发者ID:CIS-Extra,项目名称:mazes_and_minotaurs,代码行数:30,代码来源:SaveAndLoadPerformer.java

示例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());
}
 
开发者ID:Yakindu,项目名称:solidity-ide,代码行数:8,代码来源:ParameterBuilder.java

示例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();
}
 
开发者ID:jamesddube,项目名称:LaravelNewsApp,代码行数:9,代码来源:App.java

示例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();
}
 
开发者ID:rumangerst,项目名称:CSLMusicModStationCreator,代码行数:12,代码来源:Station.java

示例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;
}
 
开发者ID:hamilton-lima,项目名称:robolucha,代码行数:9,代码来源:DefaultGameDefinitionFileCreator.java

示例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();
    }
}
 
开发者ID:thane98,项目名称:3DSFE-Randomizer,代码行数:15,代码来源:FatesHub.java

示例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();
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:9,代码来源:ServerResource.java

示例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);
}
 
开发者ID:mauriciotogneri,项目名称:stewie,代码行数:10,代码来源:Swagger.java

示例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();
}
 
开发者ID:google,项目名称:spline,代码行数:8,代码来源:DocumentRepository.java

示例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);
}
 
开发者ID:FlavioSantoro92,项目名称:Pand,代码行数:9,代码来源:DAOJson.java

示例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;
}
 
开发者ID:CIS-Extra,项目名称:mazes_and_minotaurs,代码行数:16,代码来源:CharacterSerializer.java

示例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();
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:10,代码来源:VoxelGamesLibModule.java

示例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();
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:42,代码来源:JsonGson.java

示例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);
}
 
开发者ID:ldlood,项目名称:SpringBoot_Wechat_Sell,代码行数:7,代码来源:JsonUtil.java


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