diff --git a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java index 66931bd1..5e0d1bc7 100644 --- a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java +++ b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java @@ -32,11 +32,15 @@ public class JsonUtils { public static final ObjectMapper OBJECTMAPPER; + public static final ObjectMapper INDENT_MAPPER; static { OBJECTMAPPER = new ObjectMapper(); OBJECTMAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); OBJECTMAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + INDENT_MAPPER = OBJECTMAPPER.copy(); + INDENT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT); } public static void writeToFile(String fileName, T obj) { @@ -135,12 +139,8 @@ public static String indentWriteAsString(T obj) { if (obj == null) { return null; } - try { - OBJECTMAPPER.enable(SerializationFeature.INDENT_OUTPUT); - String result = OBJECTMAPPER.writeValueAsString(obj); - OBJECTMAPPER.disable(SerializationFeature.INDENT_OUTPUT); - return result; + return INDENT_MAPPER.writeValueAsString(obj); } catch (Exception e) { throw new RuntimeException(e); }