看一下Spring webflux客户端的json配置示例:
ExchangeStrategies strategies = ExchangeStrategies
.builder()
.codecs(clientDefaultCodecsConfigurer -> {
//how to do the same but xml?
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(new ObjectMapper(), MediaType.APPLICATION_JSON));
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(new ObjectMapper(), MediaType.APPLICATION_JSON));
}).build();
WebClient webClient = WebClient.builder().exchangeStrategies(strategies).build();
与this one相同的问题,只是针对jaxb xml序列化。 JAXB和xml是否有解码器实现?是否可以将HttpMessageConverter用作网络客户端的解码器,以使Spring Boot控制器和客户端实现保持一致?
答案 0 :(得分:0)
我的猜测是Jaxb2XmlDecoder
包中的Jaxb2XmlEncoder
和org.springframework.http.codec.xml
类:
ExchangeStrategies.builder()
.codecs(configurer -> {
configurer.defaultCodecs().jaxb2Decoder(new Jaxb2XmlDecoder());
configurer.defaultCodecs().jaxb2Encoder(new Jaxb2XmlEncoder());
})
.build();