Search code examples
javaspringspring-webfluxspring-restcontrollerproject-reactor

Spring webflux controller: consuming POJO vs Mono?


In a controller I can write:

fun update(@RequestBody myPojo: MyPojo): Mono<Void> 

or

fun update(@RequestBody myPojo: Mono<MyPojo>): Mono<Void> 

is there any difference? will the body parsing be done in different threads? in first case will i block the main reactor thread until myPojo is parsed?


Solution

  • There's no strong runtime difference between the two; in the first case, Spring will unwrap the incoming Mono, but the decoding will still happen asynchronously.

    The only difference is that without a Mono type as an argument, you won't be able to use Reactor operators on it. So this is really about what needs to be achieved in your controller handler.