Skip to content

Deserializing a list of ints with Spring WebClient

I’m trying to communicate with a Rest service that returns a simple JSON array of ints, e.g.

[1, 2, 3, 4]

I have the following code to make the call via WebClient:

        .doOnNext { println(it) }
        .doOnError { it.printStackTrace() }

However, Spring returns me an empty Flux. If I replace the bodyToFlux call with a bodyToMono<List<Int>>, then Spring is able to deserialize the response as expected. The drawback being that I have to then manually change it back to a Flux with a redundant flatMapIterable { it }

Am I missing something or are bodyToFlux and bodyToMono only meant to be used with Jackson POJOs?



This is a bug in Spring’s WebClient implementation.

4 People found this is helpful