Issue
I am trying to map through a mono and return a value from its field but that block is not getting called for some reason? I am trying to return a string from the method, I wonder if that is where I am going wrong and if it should be something else?
public String function getId(String name, Flux<Shift> shifts){
Mono<Shift> shift= shifts.filter(s-> s.getName().equals(name)).singleOrEmpty();
shift.map(u-> {
System.out.println("gets to here");
if(u.getId()!=null){
return u.getId()
}
return null;
})
return null;
}
I dont see the print statement which means that bit of the code is not reached. Any help would be appreciated...
Solution
You are configuring the reactor, but not executing it.
If this is the end of the reactive part, you can change it to
return shift.map(u-> {
System.out.println("gets to here");
if(u.getId()!=null){
return u.getId()
}
return null;
})
.block();
Otherwise, consider changing the return type of the method to Mono<String>
Answered By - Nikolay
Answer Checked By - Mildred Charles (JavaFixing Admin)