How to customize SpringWebFlux WebClient JSON deserialization?

后端 未结 6 498
我在风中等你
我在风中等你 2020-12-06 04:15

I\'m using a spring-webflux WebClient (build 20170502.221452-172) to access a Web application producing a stream of Entry objects (application/stream+json) like th

6条回答
  •  旧时难觅i
    2020-12-06 04:54

    Since Spring 5.1.13 you can use a dedicated .codec method to customize them:

    WebClient.builder()
        .codecs(configurer -> {
            configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(new ObjectMapper(), MediaType.APPLICATION_JSON));
            configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(new ObjectMapper(), MediaType.APPLICATION_JSON));
         })
        .build();
    

提交回复
热议问题