Reactive WebClient GET Request with text/html response

前端 未结 2 2105
无人及你
无人及你 2021-01-06 04:38

Currently I’m having an issue with new Spring 5 WebClient and I need some help to sort it out. The issue is:

I request some url that returns json respons

2条回答
  •  伪装坚强ぢ
    2021-01-06 05:31

    As mentioned in previous answer, you can use exchangeStrategies method,

    example:

                Flux response = WebClient.builder()
                    .baseUrl(url)
                    .exchangeStrategies(ExchangeStrategies.builder().codecs(this::acceptedCodecs).build())
                    .build()
                    .get()
                    .uri(builder.toUriString(), 1L)
                    .retrieve()
                    .bodyToFlux( // .. business logic
    
    
    private void acceptedCodecs(ClientCodecConfigurer clientCodecConfigurer) {
        clientCodecConfigurer.customCodecs().encoder(new Jackson2JsonEncoder(new ObjectMapper(), TEXT_HTML));
        clientCodecConfigurer.customCodecs().decoder(new Jackson2JsonDecoder(new ObjectMapper(), TEXT_HTML));
    }
    

提交回复
热议问题