vendredi 25 octobre 2019

Why ServerHttpResponseDecorator::writeWith return type is only Mono

I am extending 'org.springframework.http.server.reactive.ServerHttpResponseDecorator' in order to capture the response body. The method 'writeWith' has the following signature and return type

public Mono<Void> writeWith(Publisher<? extends DataBuffer> body)

I am casting the 'body' to a (Mono), since that is the type passed into the method, and then 'map' it in order to read dataBuffer from it. The big question that I cannot find an answer for is that whether in the future I get the type 'Flux' passed into the method. In that case although I could do a type check and cast it into (Flux) and then do the usual mapping and reading the buffer, the return type of the method 'writeWith' is still Mono. So is my approach correct to cast the publisher into Flux while the method return type is still Mono? I don't understand why there is no separate method for this scenario. One other question I have is that whether 'writeWith' method gets called multiple times in case the incoming publisher is Flux.




Aucun commentaire:

Enregistrer un commentaire