Skip to content

Commit

Permalink
Ensure that ObjectMapperCustomizer impls are used in runtime init
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed May 8, 2023
1 parent c59afb6 commit f925432
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,6 +101,12 @@ ResteasyReactiveJacksonProviderDefinedBuildItem jacksonRegistered() {
return new ResteasyReactiveJacksonProviderDefinedBuildItem();
}

@BuildStep
void nativeSupport(BuildProducer<RuntimeReinitializedClassBuildItem> runtimeReinitializedClassProducer) {
runtimeReinitializedClassProducer
.produce(new RuntimeReinitializedClassBuildItem(io.vertx.core.json.Json.class.getName()));
}

@BuildStep
ExceptionMapperBuildItem exceptionMappers() {
return new ExceptionMapperBuildItem(DefaultMismatchedInputException.class.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +38,12 @@ void feature(BuildProducer<FeatureBuildItem> features) {
features.produce(new FeatureBuildItem(REST_CLIENT_REACTIVE_JACKSON));
}

@BuildStep
void nativeSupport(BuildProducer<RuntimeReinitializedClassBuildItem> runtimeReinitializedClassProducer) {
runtimeReinitializedClassProducer
.produce(new RuntimeReinitializedClassBuildItem(io.vertx.core.json.Json.class.getName()));
}

@BuildStep
void additionalProviders(
List<ResteasyReactiveJacksonProviderDefinedBuildItem> jacksonProviderDefined,
Expand Down
6 changes: 6 additions & 0 deletions integration-tests/resteasy-reactive-kotlin/standard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,18 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
<environmentVariables>
<TEST_PROP>prod</TEST_PROP>
</environmentVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
<environmentVariables>
<TEST_PROP>prod</TEST_PROP>
</environmentVariables>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}

0 comments on commit f925432

Please sign in to comment.