I\'m trying out the new WebClient
from Spring 5 (5.0.0.RC2) in a codebase that uses reactive programming and I\'ve had success mapping the JSON response from an
Oleg Estekhin's answer gives the OP what he asked for, but it's loading the entire response content in the memory, which is an issue for large responses. To get a chunk of bytes at a time instead, we can do the following:
client.get()
.uri("uri")
.exchange()
.flatMapMany { it.body(BodyExtractors.toDataBuffers()) }
The size of these buffers would be 8192 kb by default; see this answer for changing that if needed.
Note that attempting to do dataBuffer.asByteBuffer().array()
thrwos an exception if the ByteBuffer
is not backed by an array.