Skip to content

Commit

Permalink
chore: review-based changes (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverrehu authored Feb 22, 2024
1 parent 6f4a0f1 commit c54d5dc
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/main/java/com/purbon/kafka/topology/utils/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> toMap(String jsonString) throws JsonProcessingException {
Expand All @@ -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<String> toArray(String jsonString) throws JsonProcessingException {
Expand All @@ -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)
Expand All @@ -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);
}
}

0 comments on commit c54d5dc

Please sign in to comment.