From 403ba9a6504eadcb656792d7381767ef760bd14c Mon Sep 17 00:00:00 2001 From: lhpqaq <657407891@qq.com> Date: Sun, 22 Dec 2024 23:10:52 +0800 Subject: [PATCH] fix INDENT_MAPPER --- .../apache/bigtop/manager/common/utils/JsonUtils.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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); }