Top Description Fields Constructors Methods
org.springframework.web.reactive.result.view

public Class HttpMessageWriterView

extends Object
implements View
Class Inheritance
All Implemented Interfaces
org.springframework.web.reactive.result.view.View
Imports
java.util.HashSet, .List, .Map, .Set, java.util.stream.Collectors, org.reactivestreams.Publisher, reactor.core.publisher.Mono, org.springframework.core.ResolvableType, org.springframework.core.codec.Encoder, .Hints, org.springframework.http.MediaType, org.springframework.http.codec.EncoderHttpMessageWriter, .HttpMessageWriter, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.server.ServerWebExchange

View that writes model attribute(s) with an HttpMessageWriter.
Author
Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
private final boolean
private final Set<String>
private final HttpMessageWriter<?>

Constructor Summary

AccessConstructor and Description
public
HttpMessageWriterView(Encoder<?> encoder)

Constructor with an Encoder.

public
HttpMessageWriterView(HttpMessageWriter<?> writer)

Constructor with a fully initialized HttpMessageWriter.

Method Summary

Modifier and TypeMethod and Description
public HttpMessageWriter<?>
getMessageWriter()

Return the configured message writer.

public final Set<String>
getModelKeys()

Return the configured model keys.

private Object
public List<MediaType>
getSupportedMediaTypes()

Overrides default org.springframework.web.reactive.result.view.View.getSupportedMediaTypes.

Return the list of media types this View supports, or an empty list.

private boolean
isMatch(Map.Entry<String, ?> entry)

public Mono<Void>
render(Map<String, ?>
a Map with name Strings as keys and corresponding model objects as values (Map can also be null in case of empty model)
model
,
MediaType
the content type selected to render with which should match one of the supported media types.
contentType
,
ServerWebExchange
the current exchange
exchange
)

Implements org.springframework.web.reactive.result.view.View.render.

Render the view based on the given HandlerResult.

public void
setModelKeys(Set<String> modelKeys)

Set the attributes in the model that should be rendered by this view.

private <T> Mono<Void>
write(T value, MediaType contentType, ServerWebExchange exchange)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canWriteMapback to summary
private final boolean canWriteMap
modelKeysback to summary
private final Set<String> modelKeys
writerback to summary
private final HttpMessageWriter<?> writer

Constructor Detail

HttpMessageWriterViewback to summary
public HttpMessageWriterView(Encoder<?> encoder)

Constructor with an Encoder.

HttpMessageWriterViewback to summary
public HttpMessageWriterView(HttpMessageWriter<?> writer)

Constructor with a fully initialized HttpMessageWriter.

Method Detail

getMessageWriterback to summary
public HttpMessageWriter<?> getMessageWriter()

Return the configured message writer.

getModelKeysback to summary
public final Set<String> getModelKeys()

Return the configured model keys.

getObjectToRenderback to summary
private Object getObjectToRender(Map<String, ?> model)
Annotations
@Nullable
getSupportedMediaTypesback to summary
public List<MediaType> getSupportedMediaTypes()

Overrides default org.springframework.web.reactive.result.view.View.getSupportedMediaTypes.

Doc from org.springframework.web.reactive.result.view.View.getSupportedMediaTypes.

Return the list of media types this View supports, or an empty list.

The implementation of this method for HttpMessageWriterView delegates to HttpMessageWriter#getWritableMediaTypes().

Annotations
@Override
isMatchback to summary
private boolean isMatch(Map.Entry<String, ?> entry)
renderback to summary
public Mono<Void> render(Map<String, ?> model, MediaType contentType, ServerWebExchange exchange)

Implements org.springframework.web.reactive.result.view.View.render.

Doc from org.springframework.web.reactive.result.view.View.render.

Render the view based on the given HandlerResult. Implementations can access and use the model or only a specific attribute in it.

Parameters
model:Map<String, ?>

a Map with name Strings as keys and corresponding model objects as values (Map can also be null in case of empty model)

contentType:MediaType

the content type selected to render with which should match one of the supported media types.

exchange:ServerWebExchange

the current exchange

Returns:Mono<Void>

Mono to represent when and if rendering succeeds

Annotations
@Override
@SuppressWarnings:unchecked
setModelKeysback to summary
public void setModelKeys(Set<String> modelKeys)

Set the attributes in the model that should be rendered by this view. When set, all other model attributes will be ignored. The matching attributes are further narrowed with HttpMessageWriter#canWrite. The matching attributes are processed as follows:

  • 0: nothing is written to the response body.
  • 1: the matching attribute is passed to the writer.
  • 2..N: if the writer supports Map, write all matches; otherwise raise an IllegalStateException.
writeback to summary
private <T> Mono<Void> write(T value, MediaType contentType, ServerWebExchange exchange)
Annotations
@SuppressWarnings:unchecked