Skip to content

Commit

Permalink
Load pretty mapper eagerly
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
  • Loading branch information
tsegismont committed Feb 6, 2024
1 parent 563912d commit 87aaa56
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/main/java/io/vertx/core/json/jackson/DatabindCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class DatabindCodec extends JacksonCodec {

private static final ObjectMapper mapper = new ObjectMapper();
private static final AtomicReference<ObjectMapper> prettyMapper = new AtomicReference<>();
private static final ObjectMapper prettyMapper = new ObjectMapper();

static {
initialize(mapper, false);
initialize(prettyMapper, true);
}

private static void initialize(ObjectMapper om, boolean prettyPrint) {
Expand All @@ -64,13 +64,7 @@ public static ObjectMapper mapper() {
*/
@Deprecated
public static ObjectMapper prettyMapper() {
ObjectMapper pm = prettyMapper.get();
if (pm != null) {
return pm;
}
pm = new ObjectMapper();
initialize(pm, true);
return prettyMapper.compareAndSet(null, pm) ? pm : prettyMapper.get();
return prettyMapper;
}

@Override
Expand Down

0 comments on commit 87aaa56

Please sign in to comment.