Fix compiler warning

This commit is contained in:
Rossen Stoyanchev 2017-04-06 16:08:25 -04:00
parent 584b290dff
commit b245918574
1 changed files with 9 additions and 6 deletions

View File

@ -117,12 +117,7 @@ public class HttpMessageWriterView implements View {
@SuppressWarnings("unchecked")
public Mono<Void> render(Map<String, ?> model, MediaType contentType, ServerWebExchange exchange) {
return getObjectToRender(model)
.map(value -> {
Publisher stream = Mono.justOrEmpty(value);
ResolvableType type = ResolvableType.forClass(value.getClass());
ServerHttpResponse response = exchange.getResponse();
return this.writer.write(stream, type, contentType, response, Collections.emptyMap());
})
.map(value -> write(value, contentType, exchange))
.orElseGet(() -> exchange.getResponse().setComplete());
}
@ -158,4 +153,12 @@ public class HttpMessageWriterView implements View {
return getMessageWriter().canWrite(type, null);
}
@SuppressWarnings("unchecked")
private <T> Mono<Void> write(T value, MediaType contentType, ServerWebExchange exchange) {
Publisher<T> input = Mono.justOrEmpty(value);
ResolvableType elementType = ResolvableType.forClass(value.getClass());
return ((HttpMessageWriter<T>) this.writer).write(
input, elementType, contentType, exchange.getResponse(), Collections.emptyMap());
}
}