I am doing testing with Wiremock and I have following example for POJO:
@Data
public class DataResponse {
private Supply supply;
private static class Supply {
private List<TimeSeries> timeSeries;
}
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public static class TimeSeries {
private LocalDate date;
}
}
And I am stubbing some external API which should response with this POJO as json:
DataResponse dataResponse = DataResponse.builder()
.supply(DataResponse.Supply.builder()
.timeSeries(List.of(
DataResponse.TimeSeries.builder()
.date("2021-11-16")
build()
))
.build()
.build()
String jsonDataResponse = mapper.writeValueAsString(dataResponse); //mapper is instance of ObjectMapper
stubFor(WireMock.get(urlEqualTo("/someUrl"))
.willReturn(aResponse()
.withBody(jsonDataResponse)));
The issue is when I do serialization with ObjectMapper I get "timeSeries" instead of "time_series". Is there any way to get the right JSON string format only with changes in the test file?