Ram Viswanathan
Ram Viswanathan

Reputation: 201

Modifying the value of a Mono and forming a different object

I have a service that returns a Mono. In my controller, when I get the Mono, I would like to modify the A to another object B and return B.

How can I do this?

Upvotes: 1

Views: 1768

Answers (1)

Ranjith
Ranjith

Reputation: 1739

Mono.map() function can be used for modifying the item emitted by the Mono.

Example:

Mono<A> aMono = Mono.just(new A());
Mono<B> bMono = aMono.map(a -> {
    B b = new B();
    b.setS(a.getS());
    return b;
});

Upvotes: 2

Related Questions