0
votes

I have a Mono object Mono<User> which I want to convert to object in a reactive way.

context.getUser().map(User::getUserId);

Here, context.getUser() returns Mono<User> and I can get userId from there. How to get the complete object?

1

1 Answers

3
votes
context.getUser().map(user -> {
  // here you have the "complete" user object in variable "user"
});

if you need to store the value in a variable, you can do it like

User user = context.getUser().block();

but that's not advisable:

you should avoid this by favoring having reactive code end-to-end, as much as possible. You MUST avoid this at all cost in the middle of other reactive code, as this has the potential to lock your whole reactive pipeline.

Doing that kinda defeats the point of using reactive programming. It will then have a blocking bottleneck which is exactly the thing reactive programming attempts to avoid.