Skip to content

Commit

Permalink
Merge pull request #33189 from geoand/#32969
Browse files Browse the repository at this point in the history
Ensure that ObjectMapperCustomizer impls are used in runtime init
  • Loading branch information
geoand authored May 10, 2023
2 parents efc0f9b + 1fbb639 commit 1090afd
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import io.quarkus.resteasy.reactive.spi.ExceptionMapperBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem;
import io.quarkus.vertx.deployment.ReinitializeVertxJsonBuildItem;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

Expand Down Expand Up @@ -100,6 +101,11 @@ ResteasyReactiveJacksonProviderDefinedBuildItem jacksonRegistered() {
return new ResteasyReactiveJacksonProviderDefinedBuildItem();
}

@BuildStep
ReinitializeVertxJsonBuildItem vertxJson() {
return new ReinitializeVertxJsonBuildItem();
}

@BuildStep
ExceptionMapperBuildItem exceptionMappers() {
return new ExceptionMapperBuildItem(DefaultMismatchedInputException.class.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.quarkus.resteasy.reactive.jackson.runtime.serialisers.vertx.VertxJsonObjectBasicMessageBodyWriter;
import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem;
import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem;
import io.quarkus.vertx.deployment.ReinitializeVertxJsonBuildItem;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

Expand All @@ -37,6 +38,11 @@ void feature(BuildProducer<FeatureBuildItem> features) {
features.produce(new FeatureBuildItem(REST_CLIENT_REACTIVE_JACKSON));
}

@BuildStep
ReinitializeVertxJsonBuildItem vertxJson() {
return new ReinitializeVertxJsonBuildItem();
}

@BuildStep
void additionalProviders(
List<ResteasyReactiveJacksonProviderDefinedBuildItem> jacksonProviderDefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkus.vertx.deployment;

import io.quarkus.builder.item.MultiBuildItem;

/**
* Marker build item used to force the re-initialization of Vert.x JSON handling in native-image
*/
public final class ReinitializeVertxJsonBuildItem extends MultiBuildItem {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.quarkus.vertx.deployment;

import java.util.List;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.vertx.core.spi.JsonFactory;

public class VertxJsonProcessor {

@BuildStep
void nativeSupport(List<ReinitializeVertxJsonBuildItem> reinitializeVertxJson,
BuildProducer<RuntimeReinitializedClassBuildItem> runtimeReinitializedClassProducer,
BuildProducer<ServiceProviderBuildItem> serviceProviderBuildItemBuildProducer) {
if (reinitializeVertxJson.isEmpty()) {
return;
}
runtimeReinitializedClassProducer
.produce(new RuntimeReinitializedClassBuildItem(io.vertx.core.json.Json.class.getName()));
runtimeReinitializedClassProducer
.produce(new RuntimeReinitializedClassBuildItem("io.quarkus.vertx.runtime.jackson.QuarkusJacksonJsonCodec"));
serviceProviderBuildItemBuildProducer
.produce(ServiceProviderBuildItem.allProvidersFromClassPath(JsonFactory.class.getName()));
}
}
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 1090afd

Please sign in to comment.