Skip to content

Commit

Permalink
fix INDENT_MAPPER
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Dec 22, 2024
1 parent ce4e5b3 commit 403ba9a
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> void writeToFile(String fileName, T obj) {
Expand Down Expand Up @@ -135,12 +139,8 @@ public static <T> 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);
}
Expand Down

0 comments on commit 403ba9a

Please sign in to comment.