Ashane.E
Ashane.E

Reputation: 131

How to access attributes returned as a Mono object separately using Springboot

I developed a REST service with the help of reactive programming in Spring Boot.I was able to retrieve the data as a mono object.But I need to capture only the necessary attribute from that Mono object returned

public Mono<Boolean> getUserAddress(User userRequest) {
    Mono<User> user =  userRepository.findByUsername(userRequest.getUsername());

   return user.filter(usr -> true).hasElement();
}

This code return true when there is data returned for a relevant username. But what I actually want is to retrieve only the "address" attribute from that returned Mono object and do some other processing.

FYI - Mono object returning works fine in my code

Upvotes: 1

Views: 4135

Answers (1)

ŁukaszG
ŁukaszG

Reputation: 624

Use a simple map.

user.map(usr -> usr.getWhatYouWant())

Your code is wrong, anyway. Filter will not filter anything.

Upvotes: 2

Related Questions