From c54d5dc1c3ba74ffaf85ea4fb6542bb39a4cd3a5 Mon Sep 17 00:00:00 2001 From: "Sverre H. Huseby" Date: Thu, 22 Feb 2024 13:53:52 +0100 Subject: [PATCH] chore: review-based changes (#16) --- .../java/com/purbon/kafka/topology/utils/JSON.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/purbon/kafka/topology/utils/JSON.java b/src/main/java/com/purbon/kafka/topology/utils/JSON.java index 4e3fad835..aa858c0b5 100644 --- a/src/main/java/com/purbon/kafka/topology/utils/JSON.java +++ b/src/main/java/com/purbon/kafka/topology/utils/JSON.java @@ -14,11 +14,15 @@ public class JSON { private static final ObjectMapper mapper; + private static final ObjectWriter prettyWriter; static { mapper = new ObjectMapper(); mapper.registerModule(new Jdk8Module()); mapper.findAndRegisterModules(); + DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter(); + prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE); + prettyWriter = mapper.writer(prettyPrinter); } public static Map toMap(String jsonString) throws JsonProcessingException { @@ -30,7 +34,7 @@ public static String asString(Map map) throws JsonProcessingException { } public static String asPrettyString(Map map) throws JsonProcessingException { - return getPrettyWriter().writeValueAsString(map); + return prettyWriter.writeValueAsString(map); } public static List toArray(String jsonString) throws JsonProcessingException { @@ -42,7 +46,7 @@ public static String asString(Object object) throws JsonProcessingException { } public static String asPrettyString(Object object) throws JsonProcessingException { - return getPrettyWriter().writeValueAsString(object); + return prettyWriter.writeValueAsString(object); } public static Object toObjectList(String jsonString, Class objectClazz) @@ -60,10 +64,4 @@ public static Object toObject(String jsonString, Class objectClazz) public static JsonNode toNode(String jsonString) throws JsonProcessingException { return mapper.readTree(jsonString); } - - private static ObjectWriter getPrettyWriter() { - DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter(); - prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE); - return mapper.writer(prettyPrinter); - } }