Repository: quarkusio/quarkus
Issue: Resteasy Reactive: ContextResolver<ObjectMapper> not used

### Describe the bug

When creating a RestClient with a `ContextResolver<ObjectMapper>` registered, this ContextResolver is never used and thus the wrong ObjectMapper (via CDI) is used. Other implementation approaches would be fine as well, but nothing seems to get this behaviour working. Multiple different ObjectMappers in the application do not seem to be supported.

### Expected behavior

The ObjectMapper returned by a class that implements `ContextResolver<ObjectMapper>` used via `RestClientBuilder#register(Object)` is used in the given RestClient and only there.
Multiple RestClients can use multiple different ObjectMappers.

### Actual behavior

The ObjectMapper of the registered `ContextResolver` is not used at all. Instead an application scoped ObjectMapper bean is used in all RestClients.

### How to Reproduce?

Run the following test class. The test should pass if matching the expected behaviour.

```java
@QuarkusTest
class MyClientTest {

    MyClient clientAllowsUnknown;
    MyClient clientDisallowsUnknown;

    WireMockServer wireMockServer = getWireMockServer();

    @BeforeEach
    void setUp() throws MalformedURLException {
        wireMockServer.resetAll();

        clientAllowsUnknown = RestClientBuilder.newBuilder()
            .baseUrl(new URL(wireMockServer.baseUrl()))
            .register(ClientObjectMapperUnknown.class)
            .build(MyClient.class);

        clientDisallowsUnknown = RestClientBuilder.newBuilder()
            .baseUrl(new URL(wireMockServer.baseUrl()))
            .register(ClientObjectMapperNoUnknown.class)
            .build(MyClient.class);
    }

    @Test
    void something_withAdditionalIgnoredProperties() {
        var json = "{ \\"value\\": \\"someValue\\", \\"secondValue\\": \\"toBeIgnored\\" }";
        wireMockServer.stubFor(
            WireMock.get(WireMock.urlMatching("/something"))
                .willReturn(okJson(json)));

        var result = clientAllowsUnknown.something().await().indefinitely();

        // FAIL_ON_UNKNOWN_PROPERTIES disabled
        assertThatCode(() -> new ClientObjectMapperUnknown().getContext(ObjectMapper.class).readValue(json, Something.class))
            .doesNotThrowAnyException();
        assertThat(result).isEqualTo(Something.builder().withValue("someValue").build());

        // FAIL_ON_UNKNOWN_PROPERTIES enabled
        assertThatThrownBy(() -> new ClientObjectMapperNoUnknown().getContext(ObjectMapper.class).readValue(json, Something.class))
            .isInstanceOf(JsonProcessingException.class);
        assertThatThrownBy(() -> clientDisallowsUnknown.something().await().indefinitely())
            .isInstanceOf(JsonProcessingException.class);
    }

    @Path("/something")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public interface MyClient {
        @GET
        Uni<Something> something();
    }

    @Value
    @Builder(toBuilder = true, setterPrefix = "with")
    @Jacksonized
    public static class Something {
        String value;
    }

    public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> {
        @Override
        public ObjectMapper getContext(Class<?> type) {
            return new ObjectMapper()
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
        }
    }

    public static class ClientObjectMapperNoUnknown implements ContextResolver<ObjectMapper> {
        @Override
        public ObjectMapper getContext(Class<?> type) {
            return new ObjectMapper()
                .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .enable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
        }
    }

    public static WireMockServer getWireMockServer() {
        var wireMockServer = new WireMockServer(options().port(getAvailableTcpPort(20000, 22000)));
        wireMockServer.start();
        return wireMockServer;
    }

    public static int getAvailableTcpPort(int min, int max) {
        var ports = IntStream.range(min, max).boxed().collect(Collectors.toList());
        Collections.shuffle(ports); // shuffle to get a random order and reduce the probability a port is already in use

        for (var port : ports) {
            try (ServerSocket serverSocket = new ServerSocket(port)) {
                return serverSocket.getLocalPort();
            } catch (IOException e) {
                // try next
            }
        }

        throw new IllegalStateException(MessageFormat.format("Could not find a free TCP port in range {0}:{1}.", min, max));
    }
}
```

With
```xml
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-client-reactive-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy-reactive</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.22</version>
        </dependency>
```

### Output of `uname -a` or `ver`

Darwin M042112251A.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:07 PST 2021; root:xnu-7195.141.14~1/RELEASE_X86_64 x86_64

### Output of `java -version`

openjdk version "11.0.14.1" 2022-02-08 OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1) OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)

### GraalVM version (if different from Java)

not used

### Quarkus version or git rev

2.8.0.Final, 2.9.2.Final, 2.10.0.CR1

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

### Additional information

_No response_

Changed files:
extensions/resteasy-reactive/rest-client-reactive-jackson/runtime/src/main/java/io/quarkus/rest/client/reactive/jackson/runtime/serialisers/ClientJacksonMessageBodyWriter.java
integration-tests/rest-client-reactive/src/test/java/io/quarkus/it/rest/client/ClientWithCustomObjectMapperTest.java

diff --git a/extensions/resteasy-reactive/rest-client-reactive-jackson/runtime/src/main/java/io/quarkus/rest/client/reactive/jackson/runtime/serialisers/ClientJacksonMessageBodyWriter.java b/extensions/resteasy-reactive/rest-client-reactive-jackson/runtime/src/main/java/io/quarkus/rest/client/reactive/jackson/runtime/serialisers/ClientJacksonMessageBodyWriter.java
index 1ba281fc8c3..98a52d39391 100644
--- a/extensions/resteasy-reactive/rest-client-reactive-jackson/runtime/src/main/java/io/quarkus/rest/client/reactive/jackson/runtime/serialisers/ClientJacksonMessageBodyWriter.java
+++ b/extensions/resteasy-reactive/rest-client-reactive-jackson/runtime/src/main/java/io/quarkus/rest/client/reactive/jackson/runtime/serialisers/ClientJacksonMessageBodyWriter.java
@@ -49,7 +49,7 @@ public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] anno
 
     @Override
     public void handle(RestClientRequestContext requestContext) throws Exception {
-        this.context = context;
+        this.context = requestContext;
     }
 
     protected ObjectWriter getEffectiveWriter() {
diff --git a/integration-tests/rest-client-reactive/src/test/java/io/quarkus/it/rest/client/ClientWithCustomObjectMapperTest.java b/integration-tests/rest-client-reactive/src/test/java/io/quarkus/it/rest/client/ClientWithCustomObjectMapperTest.java
index b4a80c3a955..f925704718c 100644
--- a/integration-tests/rest-client-reactive/src/test/java/io/quarkus/it/rest/client/ClientWithCustomObjectMapperTest.java
+++ b/integration-tests/rest-client-reactive/src/test/java/io/quarkus/it/rest/client/ClientWithCustomObjectMapperTest.java
@@ -1,5 +1,6 @@
 package io.quarkus.it.rest.client;
 
+import static com.github.tomakehurst.wiremock.client.WireMock.ok;
 import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -8,9 +9,11 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import jakarta.ws.rs.Consumes;
 import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
 import jakarta.ws.rs.Path;
 import jakarta.ws.rs.Produces;
 import jakarta.ws.rs.core.MediaType;
@@ -40,6 +43,8 @@ public class ClientWithCustomObjectMapperTest {
 
     @BeforeEach
     public void setUp() throws MalformedURLException {
+        ClientObjectMapperUnknown.USED.set(false);
+        ClientObjectMapperNoUnknown.USED.set(false);
         wireMockServer = new WireMockServer(options().port(20001));
         wireMockServer.start();
 
@@ -60,10 +65,10 @@ public void tearDown() {
     }
 
     @Test
-    void testCustomObjectMappersShouldBeUsed() {
+    void testCustomObjectMappersShouldBeUsedInReader() {
         var json = "{ \\"value\\": \\"someValue\\", \\"secondValue\\": \\"toBeIgnored\\" }";
         wireMockServer.stubFor(
-                WireMock.get(WireMock.urlMatching("/get"))
+                WireMock.get(WireMock.urlMatching("/client"))
                         .willReturn(okJson(json)));
 
         // FAIL_ON_UNKNOWN_PROPERTIES disabled
@@ -75,12 +80,25 @@ void testCustomObjectMappersShouldBeUsed() {
                 .isInstanceOf(ClientWebApplicationException.class);
     }
 
-    @Path("/get")
+    @Test
+    void testCustomObjectMappersShouldBeUsedInWriter() {
+        wireMockServer.stubFor(
+                WireMock.post(WireMock.urlMatching("/client"))
+                        .willReturn(ok()));
+
+        clientDisallowsUnknown.post(new Request());
+        assertThat(ClientObjectMapperNoUnknown.USED.get()).isTrue();
+    }
+
+    @Path("/client")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public interface MyClient {
         @GET
         Uni<Request> get();
+
+        @POST
+        void post(Request request);
     }
 
     public static class Request {
@@ -119,8 +137,11 @@ public int hashCode() {
     }
 
     public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> {
+        static final AtomicBoolean USED = new AtomicBoolean(false);
+
         @Override
         public ObjectMapper getContext(Class<?> type) {
+            USED.set(true);
             return new ObjectMapper()
                     .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                     .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
@@ -128,8 +149,12 @@ public ObjectMapper getContext(Class<?> type) {
     }
 
     public static class ClientObjectMapperNoUnknown implements ContextResolver<ObjectMapper> {
+
+        static final AtomicBoolean USED = new AtomicBoolean(false);
+
         @Override
         public ObjectMapper getContext(Class<?> type) {
+            USED.set(true);
             return new ObjectMapper()
                     .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                     .enable(SerializationFeature.FAIL_ON_EMPTY_BEANS);