public class HttpMessageWriterView extends java.lang.Object implements View
View
that writes model attribute(s) with an HttpMessageWriter
.Modifier and Type | Field and Description |
---|---|
private boolean |
canWriteMap |
private java.util.Set<java.lang.String> |
modelKeys |
private HttpMessageWriter<?> |
writer |
Constructor and Description |
---|
HttpMessageWriterView(Encoder<?> encoder)
Constructor with an
Encoder . |
HttpMessageWriterView(HttpMessageWriter<?> writer)
Constructor with a fully initialized
HttpMessageWriter . |
Modifier and Type | Method and Description |
---|---|
HttpMessageWriter<?> |
getMessageWriter()
Return the configured message writer.
|
java.util.Set<java.lang.String> |
getModelKeys()
Return the configured model keys.
|
private java.lang.Object |
getObjectToRender(java.util.Map<java.lang.String,?> model) |
java.util.List<MediaType> |
getSupportedMediaTypes()
Return the list of media types this View supports, or an empty list.
|
private boolean |
isMatch(java.util.Map.Entry<java.lang.String,?> entry) |
<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)
Set the attributes in the model that should be rendered by this view.
|
private <T> <any> |
write(T value,
MediaType contentType,
ServerWebExchange exchange) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isRedirectView
private final HttpMessageWriter<?> writer
private final java.util.Set<java.lang.String> modelKeys
private final boolean canWriteMap
public HttpMessageWriterView(Encoder<?> encoder)
Encoder
.public HttpMessageWriterView(HttpMessageWriter<?> writer)
HttpMessageWriter
.public HttpMessageWriter<?> getMessageWriter()
public java.util.List<MediaType> getSupportedMediaTypes()
The implementation of this method for HttpMessageWriterView
delegates to HttpMessageWriter.getWritableMediaTypes()
.
getSupportedMediaTypes
in interface View
public void setModelKeys(@Nullable java.util.Set<java.lang.String> modelKeys)
HttpMessageWriter.canWrite(org.springframework.core.ResolvableType, org.springframework.http.MediaType)
.
The matching attributes are processed as follows:
Map
, write all matches;
otherwise raise an IllegalStateException
.
public final java.util.Set<java.lang.String> getModelKeys()
public <any> render(@Nullable java.util.Map<java.lang.String,?> model, @Nullable 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
- a 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 succeeds@Nullable private java.lang.Object getObjectToRender(@Nullable java.util.Map<java.lang.String,?> model)
private boolean isMatch(java.util.Map.Entry<java.lang.String,?> entry)
private <T> <any> write(T value, @Nullable MediaType contentType, ServerWebExchange exchange)