|
|
|
@ -20,7 +20,6 @@ import java.util.Collections; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@ -32,7 +31,6 @@ import org.springframework.core.codec.Encoder; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.codec.EncoderHttpMessageWriter; |
|
|
|
import org.springframework.http.codec.EncoderHttpMessageWriter; |
|
|
|
import org.springframework.http.codec.HttpMessageWriter; |
|
|
|
import org.springframework.http.codec.HttpMessageWriter; |
|
|
|
import org.springframework.http.server.reactive.ServerHttpResponse; |
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
|
|
|
|
|
|
|
|
@ -116,25 +114,26 @@ public class HttpMessageWriterView implements View { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public Mono<Void> render(Map<String, ?> model, MediaType contentType, ServerWebExchange exchange) { |
|
|
|
public Mono<Void> render(Map<String, ?> model, MediaType contentType, ServerWebExchange exchange) { |
|
|
|
return getObjectToRender(model) |
|
|
|
Object value = getObjectToRender(model); |
|
|
|
.map(value -> write(value, contentType, exchange)) |
|
|
|
return (value != null) ? |
|
|
|
.orElseGet(() -> exchange.getResponse().setComplete()); |
|
|
|
write(value, contentType, exchange) : |
|
|
|
|
|
|
|
exchange.getResponse().setComplete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Optional<Object> getObjectToRender(Map<String, ?> model) { |
|
|
|
private Object getObjectToRender(Map<String, ?> model) { |
|
|
|
|
|
|
|
|
|
|
|
Map<String, ?> result = model.entrySet().stream() |
|
|
|
Map<String, ?> result = model.entrySet().stream() |
|
|
|
.filter(this::isMatch) |
|
|
|
.filter(this::isMatch) |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
|
|
|
|
|
|
|
|
|
|
|
if (result.isEmpty()) { |
|
|
|
if (result.isEmpty()) { |
|
|
|
return Optional.empty(); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (result.size() == 1) { |
|
|
|
else if (result.size() == 1) { |
|
|
|
return Optional.of(result.values().iterator().next()); |
|
|
|
return result.values().iterator().next(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (this.canWriteMap) { |
|
|
|
else if (this.canWriteMap) { |
|
|
|
return Optional.of(result); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
throw new IllegalStateException("Multiple matches found: " + result + " but " + |
|
|
|
throw new IllegalStateException("Multiple matches found: " + result + " but " + |
|
|
|
|