Skip to content

Commit

Permalink
Fix thread safety in Json.mapper() (refs #4672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Uria Valle authored and frantuma committed Sep 23, 2024
1 parent 5fc5d0e commit 9b0326b
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

public class Json {

private static ObjectMapper mapper;
private static final class ObjectMapperHolder {
private static final ObjectMapper MAPPER = ObjectMapperFactory.createJson();
}

public static ObjectMapper mapper() {
if (mapper == null) {
mapper = ObjectMapperFactory.createJson();
}
return mapper;
return ObjectMapperHolder.MAPPER;
}

public static ObjectWriter pretty() {
Expand Down

0 comments on commit 9b0326b

Please sign in to comment.