public class HttpMessageWriterView extends java.lang.Object implements View
View
that delegates to an HttpMessageWriter
.Modifier and Type | Field and Description |
---|---|
private java.util.List<MediaType> |
mediaTypes |
private HttpMessageWriter<?> |
messageWriter |
private java.util.Set<java.lang.String> |
modelKeys |
Constructor and Description |
---|
HttpMessageWriterView(Encoder<?> encoder)
|
HttpMessageWriterView(HttpMessageWriter<?> messageWriter)
Create a View that delegates to the given message messageWriter.
|
Modifier and Type | Method and Description |
---|---|
private <T> <any> |
applyMessageWriter(java.lang.Object value,
MediaType contentType,
ServerWebExchange exchange) |
protected java.lang.Object |
extractObjectToRender(java.util.Map<java.lang.String,?> model) |
HttpMessageWriter<?> |
getMessageWriter()
Return the configured message messageWriter.
|
java.util.Set<java.lang.String> |
getModelKeys()
Return the configured model keys.
|
java.util.List<MediaType> |
getSupportedMediaTypes()
Return the list of media types this View supports, or an empty list.
|
protected boolean |
isEligibleAttribute(java.lang.String attributeName,
java.lang.Object attributeValue)
Whether the given model attribute key-value pair is eligible for encoding.
|
<any> |
render(java.util.Map<java.lang.String,?> model,
MediaType contentType,
ServerWebExchange exchange)
Render the view based on the given
HandlerResult . |
void |
setModelKeys(java.util.Set<java.lang.String> modelKeys)
By default model attributes are filtered with
HttpMessageWriter.canWrite(org.springframework.core.ResolvableType, org.springframework.http.MediaType) to find the ones that can be
rendered. |
private final HttpMessageWriter<?> messageWriter
private final java.util.Set<java.lang.String> modelKeys
private final java.util.List<MediaType> mediaTypes
public HttpMessageWriterView(Encoder<?> encoder)
public HttpMessageWriterView(HttpMessageWriter<?> messageWriter)
public HttpMessageWriter<?> getMessageWriter()
public void setModelKeys(java.util.Set<java.lang.String> modelKeys)
HttpMessageWriter.canWrite(org.springframework.core.ResolvableType, org.springframework.http.MediaType)
to find the ones that can be
rendered. Use this property to further narrow the list and consider only
attribute(s) under specific model key(s).
If more than one matching attribute is found, than a Map is rendered,
or if the Encoder
does not support rendering a Map
then
an exception is raised.
public final java.util.Set<java.lang.String> getModelKeys()
public java.util.List<MediaType> getSupportedMediaTypes()
View
getSupportedMediaTypes
in interface View
public <any> render(java.util.Map<java.lang.String,?> model, MediaType contentType, ServerWebExchange exchange)
View
HandlerResult
. Implementations
can access and use the model or only a specific attribute in it.render
in interface View
model
- Map with name Strings as keys and corresponding model
objects as values (Map can also be null
in case of empty model)contentType
- the content type selected to render with which should
match one of the supported media types
.exchange
- the current exchangeMono
to represent when and if rendering succeedsprotected java.lang.Object extractObjectToRender(java.util.Map<java.lang.String,?> model)
protected boolean isEligibleAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
The default implementation checks against the configured
model keys
and whether the Encoder supports the
value type.
private <T> <any> applyMessageWriter(java.lang.Object value, MediaType contentType, ServerWebExchange exchange)