Index: ssts-web/src/test/java/test/forgon/disinfectsystem/selenium3/Utils.java =================================================================== diff -u -r34449 -r35637 --- ssts-web/src/test/java/test/forgon/disinfectsystem/selenium3/Utils.java (.../Utils.java) (revision 34449) +++ ssts-web/src/test/java/test/forgon/disinfectsystem/selenium3/Utils.java (.../Utils.java) (revision 35637) @@ -52,6 +52,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.forgon.tools.util.ConfigUtils; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; /** * 工具类 * @author yuandongxiao @@ -166,6 +173,7 @@ */ public static void setConfigJs(String key , Object value){ JSONObject jsonObj = null; + String jsonObj1=null; ObjectMapper mapper = new ObjectMapper().configure(Feature.ALLOW_COMMENTS, true); mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true); @@ -183,8 +191,13 @@ } jsonObj = mapper.readValue(content,JSONObject.class); jsonObj.put(key, value); + + //格式化输出的JSON文件,即config.js + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + jsonObj1=gson.toJson(jsonObj); + String writeContent = jsonHeadContent; - writeContent += jsonObj; + writeContent += jsonObj1; FileWriter writer = new FileWriter(new File(rootPath + configFilePath)); writer.write(writeContent); writer.flush(); @@ -198,6 +211,19 @@ } } + + +/** + * 格式化输出JSON字符串 + * @return 格式化后的JSON字符串 + */ +private static String toPrettyFormat(String json) { + JsonParser jsonParser = new JsonParser(); + JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + return gson.toJson(jsonObject); + } + /** * 配置config.js文件 */