How can I intercept WebFilter
requests after they have been converted from DTO to JSON String?
Of course I could add a ExchangeFilterFunction
, but the clientRequest.body()
only shows my input object, not the converted json string:
WebClient.builder().defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).filter(logRequest()).build();
private ExchangeFilterFunction logRequest() {
return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
LOGGER.info(clientRequest.body()); //body is MyRequest.class
return Mono.just(clientRequest);
});
}
MyRequestDto dto;
client.post().uri(url).syncBody(dto).retrieve().bodyToMono(MyResponseDto.class).block();
So I'm looking for a way to intercept the outgoing requests after they have been converted from dto to json string.
And the other way around, intercept responses before they are converted to dto from json.