Skip to content

Commit ce76587

Browse files
authored
Merge pull request #31422 from Sgitario/26152_a
Fix client jackson body writer to propagate the client context
2 parents cb1f0fc + e05af28 commit ce76587

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

extensions/resteasy-reactive/rest-client-reactive-jackson/runtime/src/main/java/io/quarkus/rest/client/reactive/jackson/runtime/serialisers/ClientJacksonMessageBodyWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] anno
4949

5050
@Override
5151
public void handle(RestClientRequestContext requestContext) throws Exception {
52-
this.context = context;
52+
this.context = requestContext;
5353
}
5454

5555
protected ObjectWriter getEffectiveWriter() {

integration-tests/rest-client-reactive/src/test/java/io/quarkus/it/rest/client/ClientWithCustomObjectMapperTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.it.rest.client;
22

3+
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
34
import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
45
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
56
import static org.assertj.core.api.Assertions.assertThat;
@@ -8,9 +9,11 @@
89
import java.net.MalformedURLException;
910
import java.net.URL;
1011
import java.util.Objects;
12+
import java.util.concurrent.atomic.AtomicBoolean;
1113

1214
import jakarta.ws.rs.Consumes;
1315
import jakarta.ws.rs.GET;
16+
import jakarta.ws.rs.POST;
1417
import jakarta.ws.rs.Path;
1518
import jakarta.ws.rs.Produces;
1619
import jakarta.ws.rs.core.MediaType;
@@ -40,6 +43,8 @@ public class ClientWithCustomObjectMapperTest {
4043

4144
@BeforeEach
4245
public void setUp() throws MalformedURLException {
46+
ClientObjectMapperUnknown.USED.set(false);
47+
ClientObjectMapperNoUnknown.USED.set(false);
4348
wireMockServer = new WireMockServer(options().port(20001));
4449
wireMockServer.start();
4550

@@ -60,10 +65,10 @@ public void tearDown() {
6065
}
6166

6267
@Test
63-
void testCustomObjectMappersShouldBeUsed() {
68+
void testCustomObjectMappersShouldBeUsedInReader() {
6469
var json = "{ \"value\": \"someValue\", \"secondValue\": \"toBeIgnored\" }";
6570
wireMockServer.stubFor(
66-
WireMock.get(WireMock.urlMatching("/get"))
71+
WireMock.get(WireMock.urlMatching("/client"))
6772
.willReturn(okJson(json)));
6873

6974
// FAIL_ON_UNKNOWN_PROPERTIES disabled
@@ -75,12 +80,25 @@ void testCustomObjectMappersShouldBeUsed() {
7580
.isInstanceOf(ClientWebApplicationException.class);
7681
}
7782

78-
@Path("/get")
83+
@Test
84+
void testCustomObjectMappersShouldBeUsedInWriter() {
85+
wireMockServer.stubFor(
86+
WireMock.post(WireMock.urlMatching("/client"))
87+
.willReturn(ok()));
88+
89+
clientDisallowsUnknown.post(new Request());
90+
assertThat(ClientObjectMapperNoUnknown.USED.get()).isTrue();
91+
}
92+
93+
@Path("/client")
7994
@Consumes(MediaType.APPLICATION_JSON)
8095
@Produces(MediaType.APPLICATION_JSON)
8196
public interface MyClient {
8297
@GET
8398
Uni<Request> get();
99+
100+
@POST
101+
void post(Request request);
84102
}
85103

86104
public static class Request {
@@ -119,17 +137,24 @@ public int hashCode() {
119137
}
120138

121139
public static class ClientObjectMapperUnknown implements ContextResolver<ObjectMapper> {
140+
static final AtomicBoolean USED = new AtomicBoolean(false);
141+
122142
@Override
123143
public ObjectMapper getContext(Class<?> type) {
144+
USED.set(true);
124145
return new ObjectMapper()
125146
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
126147
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
127148
}
128149
}
129150

130151
public static class ClientObjectMapperNoUnknown implements ContextResolver<ObjectMapper> {
152+
153+
static final AtomicBoolean USED = new AtomicBoolean(false);
154+
131155
@Override
132156
public ObjectMapper getContext(Class<?> type) {
157+
USED.set(true);
133158
return new ObjectMapper()
134159
.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
135160
.enable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

0 commit comments

Comments
 (0)