I have the following code this returns a Mono<List> and I need a List
var test = repo.findAll().collectList().map( a-> {
return a;
});
spring.boot.version 2.7.0
I have the following code this returns a Mono<List> and I need a List
var test = repo.findAll().collectList().map( a-> {
return a;
});
spring.boot.version 2.7.0
If repo.findAll().collectList().map( a-> {return a;})
returns a Mono<List<T>>
, you can simply add .block()
on the end to get back a List<T>
var test = repo.findAll().collectList().map( a-> {
return a;
}).block();
test
will now just be a List
Your other option is to subscribe
to it and pass in a Consumer
that consumes the List. subscribe
is a non-blocking operation. If you want to subscribe
, you need to pass in a Consumer
.
Consider this method, that takes a List<String>
(making the assumption that you get a list of String
, it can be a List of anything).
public void consume(List<String> strings) {
}
if that method is defined in the same class that your call is, you can simply do
repo.findAll().collectList().map( a-> { return a;}).subscribe(this::consume);
and it will pass the List<String>
into your method when it's available.