This documentation says: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html
ServerResponse provides access to the HTTP response. Since it is immutable, you create a ServerResponse with a builder. The builder allows you to set the response status, add response headers, and provide a body. For instance, this is how to create a response with a 200 OK status, a JSON content-type, and a body:
Mono<Person> person = ...
ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(person);
Similarly I tired to pass Mono<T>
to the body method of ServerReponse Builder but I get following error :
Code snippet :
Compilation error:
Mono<Inventory> inventoryMono=request.bodyToMono(Inventory.class);
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(inventoryMono);
However it works with below code:
ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(inventoryMono.doOnNext(inventoryRepository::save).log(),Inventory.class)
What am I missing ?