Webflux should allow SYNC xml parsing with jackson mapper:
ObjectMapper mapper = new Jackson2ObjectMapperBuilder()
.createXmlMapper(true)
.modules(new JavaTimeModule())
.build();
this.webClient = WebClient.builder()
.baseUrl("/")
.exchangeStrategies(ExchangeStrategies.builder().codecs((configurer) -> {
configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
}).build())
.build();
webClient.post().uri(url).syncBody(req).retrieve().bodyToMono(MyResponse.class).block();
Jackson in general supports sync parsing, so this should work in webflux. But result is an exception:
java.lang.UnsupportedOperationException: Non-blocking source not (yet?) support for this format (XML)
at com.fasterxml.jackson.core.JsonFactory._requireJSONFactory(JsonFactory.java:1618) ~[jackson-core-2.9.9.jar:2.9.9]
at com.fasterxml.jackson.core.JsonFactory.createNonBlockingByteArrayParser(JsonFactory.java:962) ~[jackson-core-2.9.9.jar:2.9.9]
at org.springframework.http.codec.json.Jackson2Tokenizer.tokenize(Jackson2Tokenizer.java:188) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.http.codec.json.AbstractJackson2Decoder.decodeToMono(AbstractJackson2Decoder.java:98) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.http.codec.DecoderHttpMessageReader.readMono(DecoderHttpMessageReader.java:105) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.reactive.function.BodyExtractors.lambda$readToMono$14(BodyExtractors.java:211) ~[spring-webflux-5.1.8.RELEASE.jar:5.1.8.RELEASE]
It might be sufficient to detect that the request is blocking, and therefore not calling jsonFactory.createNonBlockingByteArrayParser()
in Jackson2Tokenizer
?
Maybe related to https://github.com/spring-projects/spring-framework/issues/20256
Comment From: membersound
Still no news on this?
Comment From: bclozel
We'll consider both an Encoder
and a Decoder
implementation in #20256, so closing this issue as superseded. The other issue is still blocked, waiting for the feature to be available in Jackson.