-1

I'm new in Spring WebFlux I'm using the reactive repository to User entity from the Database :

Mono<User> user = userRepository.findById(userId);

I want to convert the Mono<User> to Mono<UserDTO>

this is my method that converts my DTO :

public UserDTO getUserResourceFromUser(User user){
    var userDTO= new UserDTO();

    userDTO.setId(user.getId());
    userDTO.setUserName(user.getUserName());


    return userDTO;
}

could you please help me to adjust my getUserResourceFromUser Method to return Mono<UserDTO> without losing non-blocking behavior?

Thanks in advance.

Dan
  • 2,952
  • 3
  • 18
  • 25
James
  • 915
  • 4
  • 16
  • 40
  • @Toerktumlare thanks for your answer. no it's not the same topic – James May 28 '22 at 18:28
  • 2
    `userRepository.findById(userId).map(user -> getUserResourceFromUser(user))` – Martin Tarjányi May 29 '22 at 09:50
  • @James it is the same topic you claiming it isnt clearly shows how little own research you have done look at what martin wrote, and look at what i posted. Please explain to me why it is not same topic? – Toerktumlare May 29 '22 at 09:57
  • @MartinTarjányi thanks for your suggestion. can you provide your example as an answer to allow me to accept it as a valid ansewer? can you provide an example with flatMap also? – James May 29 '22 at 14:19
  • @Toerktumlare it's okay now. just you didn't mention that i could use map or flatmap to covert to Mono as Martin did – James May 29 '22 at 14:20

0 Answers0