I'm using WebFlux with Reactor and creating a rest service that aggregates and transforms results from an internal service call using WebFlux webclient.
The client returns a Mono<Map<String, Optional<String>>>
which I want to disassemble in a Flux with key, value elements so that I can combine it later on.
I was thinking of converting the client response of type
Mono<Map<String, Optional<String>>> to a
Flux<Tuple<String, String>>
I know you can convert a Mono<List<String>> to a Flux<String> using responseMono.flatMapMany(Flux::fromIterable)
but I couldn't find a way to handle Maps.
You can use mono.flatMapMany(map -> Flux.fromIterable(map.entrySet())) which will give you a Flux<Entry<String, Optional<String>>>.
If you explicitly want it to be a Tuple, not an Entry, then just do:
mono.flatMapMany(map -> Flux.fromIterable(map.entrySet()))
.map(e -> Tuples.of(e.getKey(), e.getValue()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With