I am trying to use javax.ws.rs.client.Client to invoke another service. I am not getting a proper response when there is a snake casing in the request/response. The code works fine when running on a server, but it's not when trying to invoke the service using the client in Junit.
Sample code:
@BeforeEach
public void init() {
wm1.stubFor(
post("/customers")
.willReturn(
ok().withHeader("Content-type", "application/json")
.withBody(
"""
{"customer_name": "Test1",
"customer_id": "71234"
}""")));
}
@Test
void buildClientTest() {
Jsonb jsonB =
JsonbBuilder.newBuilder()
.withConfig(
new JsonbConfig()
.withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_UNDERSCORES))
.build();
Client client = ClientBuilder.newBuilder().register(jsonB).build();
CustomerResponse customerResponse =
client
.target("http://localhost:8089/customers")
.request(MediaType.APPLICATION_JSON)
.header("accept", "application/json")
.post(
Entity.entity(buildRequest(), MediaType.APPLICATION_JSON), CustomerResponse.class);
System.out.println("The response is " + customerResponse.toString());
String customerId = customerResponse.getCustomerId();
assertEquals("71234", customerId);
}