From 672acbf6520cbf1598e6f2de0cb031d41f67c98b Mon Sep 17 00:00:00 2001 From: mariofusco Date: Mon, 15 Jan 2024 15:23:04 +0100 Subject: [PATCH] Use Vert.x pool with Jackson --- .../jackson/deployment/JacksonProcessor.java | 5 ++++- extensions/jackson/runtime/pom.xml | 5 +++++ .../VertxHybridPoolObjectMapperCustomizer.java | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 extensions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/VertxHybridPoolObjectMapperCustomizer.java diff --git a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java index cdfa668c0ca34..9f7bc752e092a 100644 --- a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java +++ b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java @@ -68,6 +68,7 @@ import io.quarkus.jackson.runtime.JacksonSupportRecorder; import io.quarkus.jackson.runtime.MixinsRecorder; import io.quarkus.jackson.runtime.ObjectMapperProducer; +import io.quarkus.jackson.runtime.VertxHybridPoolObjectMapperCustomizer; import io.quarkus.jackson.spi.ClassPathJacksonModuleBuildItem; import io.quarkus.jackson.spi.JacksonModuleBuildItem; @@ -108,9 +109,11 @@ public class JacksonProcessor { List ignoreJsonDeserializeClassBuildItems; @BuildStep - void unremovable(Capabilities capabilities, BuildProducer producer) { + void unremovable(Capabilities capabilities, BuildProducer producer, + BuildProducer additionalProducer) { if (capabilities.isPresent(Capability.VERTX_CORE)) { producer.produce(UnremovableBeanBuildItem.beanTypes(ObjectMapper.class)); + additionalProducer.produce(AdditionalBeanBuildItem.unremovableOf(VertxHybridPoolObjectMapperCustomizer.class)); } } diff --git a/extensions/jackson/runtime/pom.xml b/extensions/jackson/runtime/pom.xml index c382137d4dd66..bd3e3a2159e33 100644 --- a/extensions/jackson/runtime/pom.xml +++ b/extensions/jackson/runtime/pom.xml @@ -33,6 +33,11 @@ io.quarkus quarkus-arc + + io.vertx + vertx-core + true + diff --git a/extensions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/VertxHybridPoolObjectMapperCustomizer.java b/extensions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/VertxHybridPoolObjectMapperCustomizer.java new file mode 100644 index 0000000000000..6f7bbe0cd3851 --- /dev/null +++ b/extensions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/VertxHybridPoolObjectMapperCustomizer.java @@ -0,0 +1,17 @@ +package io.quarkus.jackson.runtime; + +import com.fasterxml.jackson.core.util.JsonRecyclerPools; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.quarkus.jackson.ObjectMapperCustomizer; +import io.vertx.core.json.jackson.HybridJacksonPool; + +public class VertxHybridPoolObjectMapperCustomizer implements ObjectMapperCustomizer { + + @Override + public void customize(ObjectMapper objectMapper) { + if (objectMapper.getFactory()._getRecyclerPool() == JsonRecyclerPools.defaultPool()) { + objectMapper.getFactory().setRecyclerPool(HybridJacksonPool.getInstance()); + } + } +}