Affects: Spring Framework 6.0.5+
Issue
Spring fails to decode a JSON payload whose content has been aggregated and represented by at least 2 DataBuffer components, causing the error below to be thrown. This happens only when we have a HttpObjectAggregator
in the Netty ChannelPipeline
and the content is transformed to a Flux
publisher, regardless of whether we block or not when retrieving the data.
com.fasterxml.jackson.core.JsonParseException: Still have 1940 undecoded bytes, should not call 'feedInput'
Even though this is a specific case where we are "bypassing" the reactive nature of WebClient, and I can workaround the issue, I see this as a bug. Please let me know if I am misusing the client and Spring is not supposed to support this use-case.
How to reproduce the issue
Sample Spring Boot project with a data-source
application that serves the data and a data-client
application where the issue occurs while reading the data To reproduce this issue start both applications and invoke the /get-data-objects
endpoint on the client application.
Minimal code
WebClient configuration.
HttpClient httpClient = HttpClient.create()
.doOnChannelInit((observer, channel, remoteAddress) -> channel.pipeline()
.addAfter(NettyPipeline.HttpCodec, NettyPipeline.HttpAggregator, new HttpObjectAggregator(1048576)));
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient );
WebClient webClient = WebClient.builder().baseUrl(BASE_URL)
.clientConnector(connector)
.build();
Endpoint invocation.
webClient.get()
.uri(uriBuilder -> uriBuilder.path("/data").build())
.retrieve()
.bodyToFlux(Object.class)
.collectList()
.block();
Debugging
I suspect the issue was introduced with the changes to org.springframework.http.codec.json.Jackson2Tokenizer
in #29943.