Reputation: 389
We are using Spring Data reactive and when we call findAll
we are receiving a Flux<T>
and we want to expose this response in the API, but our API structure is
{
"status": 200,
"items": [ ... ]
}
So, we want to expose this as Mono<<Response<T>>
public class Response<T> {
private int status;
private List<T> items;
// ...
}
How to convert Flux<T>
in Mono<Response<T>>
in Spring Webflux?
Upvotes: 2
Views: 2348
Reputation: 59056
Flux<User> users = //...
Mono<Response<User>> response = users.collectList().map(items -> new Response(items));
Upvotes: 3