From f9254328f1242b8f907fac37a953e24b7b76425d Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 8 May 2023 08:24:08 +0300 Subject: [PATCH] Ensure that ObjectMapperCustomizer impls are used in runtime init Fixes: #32969 --- .../ResteasyReactiveJacksonProcessor.java | 7 +++++++ .../RestClientReactiveJacksonProcessor.java | 7 +++++++ .../resteasy-reactive-kotlin/standard/pom.xml | 6 ++++++ .../resteasy/reactive/kotlin/GreetingResource.kt | 11 +++++++++++ .../kotlin/RegisterCustomModuleCustomizer.kt | 15 +++++++++++++++ .../src/main/resources/application.properties | 2 ++ .../reactive/kotlin/GreetingResourceTest.kt | 9 +++++++++ 7 files changed, 57 insertions(+) create mode 100644 integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/RegisterCustomModuleCustomizer.kt diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/ResteasyReactiveJacksonProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/ResteasyReactiveJacksonProcessor.java index 679f4a3fbc915b..a80b6f1cfcda5b 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/ResteasyReactiveJacksonProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/ResteasyReactiveJacksonProcessor.java @@ -42,6 +42,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; import io.quarkus.resteasy.reactive.common.deployment.JaxRsResourceIndexBuildItem; import io.quarkus.resteasy.reactive.common.deployment.ResourceScanningResultBuildItem; import io.quarkus.resteasy.reactive.common.deployment.ServerDefaultProducesHandlerBuildItem; @@ -100,6 +101,12 @@ ResteasyReactiveJacksonProviderDefinedBuildItem jacksonRegistered() { return new ResteasyReactiveJacksonProviderDefinedBuildItem(); } + @BuildStep + void nativeSupport(BuildProducer runtimeReinitializedClassProducer) { + runtimeReinitializedClassProducer + .produce(new RuntimeReinitializedClassBuildItem(io.vertx.core.json.Json.class.getName())); + } + @BuildStep ExceptionMapperBuildItem exceptionMappers() { return new ExceptionMapperBuildItem(DefaultMismatchedInputException.class.getName(), diff --git a/extensions/resteasy-reactive/rest-client-reactive-jackson/deployment/src/main/java/io/quarkus/rest/client/reactive/jackson/deployment/RestClientReactiveJacksonProcessor.java b/extensions/resteasy-reactive/rest-client-reactive-jackson/deployment/src/main/java/io/quarkus/rest/client/reactive/jackson/deployment/RestClientReactiveJacksonProcessor.java index 12fe28143cc6e7..3ea2cc1dacb2c3 100644 --- a/extensions/resteasy-reactive/rest-client-reactive-jackson/deployment/src/main/java/io/quarkus/rest/client/reactive/jackson/deployment/RestClientReactiveJacksonProcessor.java +++ b/extensions/resteasy-reactive/rest-client-reactive-jackson/deployment/src/main/java/io/quarkus/rest/client/reactive/jackson/deployment/RestClientReactiveJacksonProcessor.java @@ -14,6 +14,7 @@ import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; import io.quarkus.rest.client.reactive.jackson.runtime.serialisers.ClientJacksonMessageBodyReader; import io.quarkus.rest.client.reactive.jackson.runtime.serialisers.ClientJacksonMessageBodyWriter; import io.quarkus.resteasy.reactive.jackson.deployment.processor.ResteasyReactiveJacksonProviderDefinedBuildItem; @@ -37,6 +38,12 @@ void feature(BuildProducer features) { features.produce(new FeatureBuildItem(REST_CLIENT_REACTIVE_JACKSON)); } + @BuildStep + void nativeSupport(BuildProducer runtimeReinitializedClassProducer) { + runtimeReinitializedClassProducer + .produce(new RuntimeReinitializedClassBuildItem(io.vertx.core.json.Json.class.getName())); + } + @BuildStep void additionalProviders( List jacksonProviderDefined, diff --git a/integration-tests/resteasy-reactive-kotlin/standard/pom.xml b/integration-tests/resteasy-reactive-kotlin/standard/pom.xml index bf8df26dd43540..758d622b759c33 100644 --- a/integration-tests/resteasy-reactive-kotlin/standard/pom.xml +++ b/integration-tests/resteasy-reactive-kotlin/standard/pom.xml @@ -275,12 +275,18 @@ maven-surefire-plugin false + + prod + maven-failsafe-plugin false + + prod + diff --git a/integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResource.kt b/integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResource.kt index 5adad745db57c7..c5fd5403b6aabf 100644 --- a/integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResource.kt +++ b/integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResource.kt @@ -8,11 +8,16 @@ import jakarta.ws.rs.core.Context import jakarta.ws.rs.core.HttpHeaders import jakarta.ws.rs.core.Response import jakarta.ws.rs.core.UriInfo +import java.util.concurrent.atomic.AtomicReference import org.jboss.resteasy.reactive.RestHeader @Path("/greeting") class GreetingResource(val headers: HttpHeaders) { + companion object { + val MY_PROPERTY = AtomicReference("unset") + } + @GET suspend fun testSuspend(@RestHeader("firstName") firstName: String): Greeting { val lastName = headers.getHeaderString("lastName") @@ -28,6 +33,12 @@ class GreetingResource(val headers: HttpHeaders) { greeting: Greeting, @Context uriInfo: UriInfo ) = Response.ok(greeting).build() + + @GET + @Path("prop") + fun testProp(): String? { + return MY_PROPERTY.get() + } } data class Greeting(val message: String) diff --git a/integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/RegisterCustomModuleCustomizer.kt b/integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/RegisterCustomModuleCustomizer.kt new file mode 100644 index 00000000000000..1600498fb6ad6e --- /dev/null +++ b/integration-tests/resteasy-reactive-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/RegisterCustomModuleCustomizer.kt @@ -0,0 +1,15 @@ +package io.quarkus.it.resteasy.reactive.kotlin + +import com.fasterxml.jackson.databind.ObjectMapper +import io.quarkus.jackson.ObjectMapperCustomizer +import jakarta.inject.Singleton +import org.eclipse.microprofile.config.inject.ConfigProperty + +@Singleton +class RegisterCustomModuleCustomizer : ObjectMapperCustomizer { + @ConfigProperty(name = "test.prop") lateinit var testProp: String + + override fun customize(objectMapper: ObjectMapper) { + GreetingResource.MY_PROPERTY.set(testProp) + } +} diff --git a/integration-tests/resteasy-reactive-kotlin/standard/src/main/resources/application.properties b/integration-tests/resteasy-reactive-kotlin/standard/src/main/resources/application.properties index dbd2604ffa9a1c..5e5d8b8138f0ca 100644 --- a/integration-tests/resteasy-reactive-kotlin/standard/src/main/resources/application.properties +++ b/integration-tests/resteasy-reactive-kotlin/standard/src/main/resources/application.properties @@ -29,3 +29,5 @@ mp.messaging.incoming.countries-t2-in.auto.offset.reset=earliest mp.messaging.incoming.countries-t2-in.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer quarkus.package.quiltflower.enabled=true + +test.prop=test diff --git a/integration-tests/resteasy-reactive-kotlin/standard/src/test/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResourceTest.kt b/integration-tests/resteasy-reactive-kotlin/standard/src/test/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResourceTest.kt index 226058ffe4da68..2541a7a53f9083 100644 --- a/integration-tests/resteasy-reactive-kotlin/standard/src/test/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResourceTest.kt +++ b/integration-tests/resteasy-reactive-kotlin/standard/src/test/kotlin/io/quarkus/it/resteasy/reactive/kotlin/GreetingResourceTest.kt @@ -39,4 +39,13 @@ class GreetingResourceTest { fun testNoopCoroutine() { When { get("/greeting/noop") } Then { statusCode(204) } } + + @Test + fun testProp() { + When { get("/greeting/prop") } Then + { + statusCode(200) + body(CoreMatchers.`is`("prod")) + } + } }