Skip to content

Commit

Permalink
[Improve][JsonUtils] Use a static object mapper instead of creating i…
Browse files Browse the repository at this point in the history
…t every time (apache#5460)
  • Loading branch information
Morssssy authored and gnehil committed Oct 12, 2023
1 parent 3271e0b commit 4467816
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class JsonUtils {
.configure(REQUIRE_SETTERS_FOR_GETTERS, true)
.setTimeZone(TimeZone.getDefault());

private static final ObjectMapper DEFAULT_OBJECT_MAPPER = new ObjectMapper();

private JsonUtils() {
throw new UnsupportedOperationException("Construct JSONUtils");
}
Expand Down Expand Up @@ -172,8 +174,8 @@ public static Map<String, String> toMap(String json) {
}

public static Map<String, Object> toMap(JsonNode jsonNode) {
ObjectMapper mapper = new ObjectMapper();
return mapper.convertValue(jsonNode, new TypeReference<Map<String, Object>>() {});
return DEFAULT_OBJECT_MAPPER.convertValue(
jsonNode, new TypeReference<Map<String, Object>>() {});
}

/**
Expand Down

0 comments on commit 4467816

Please sign in to comment.