Deserializing a list of ints with Spring WebClient

Tags: , , ,



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:

    client.get()
        .uri("/achievements")
        .retrieve()
        .bodyToFlux<Int>()
        .doOnNext { println(it) }
        .doOnError { it.printStackTrace() }
        .blockLast()

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?

Answer

This is a bug in Spring’s WebClient implementation.



Source: stackoverflow