org.springframework.web.reactive.result.view

Class HttpMessageWriterView

  • java.lang.Object
    • org.springframework.web.reactive.result.view.HttpMessageWriterView
  • All Implemented Interfaces:
    View


    public class HttpMessageWriterView
    extends java.lang.Object
    implements View
    View that writes model attribute(s) with an HttpMessageWriter.
    Since:
    5.0
    Author:
    Rossen Stoyanchev
    • Constructor Detail

      • HttpMessageWriterView

        public HttpMessageWriterView(Encoder<?> encoder)
        Constructor with an Encoder.
    • Method Detail

      • getMessageWriter

        public HttpMessageWriter<?> getMessageWriter()
        Return the configured message writer.
      • setModelKeys

        public void setModelKeys(@Nullable
                                 java.util.Set<java.lang.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(org.springframework.core.ResolvableType, org.springframework.http.MediaType). 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.
      • getModelKeys

        public final java.util.Set<java.lang.String> getModelKeys()
        Return the configured model keys.
      • render

        public reactor.core.publisher.Mono<java.lang.Void> render(@Nullable
                                                                  java.util.Map<java.lang.String,?> model,
                                                                  @Nullable
                                                                  MediaType contentType,
                                                                  ServerWebExchange exchange)
        Description copied from interface: View
        Render the view based on the given HandlerResult. Implementations can access and use the model or only a specific attribute in it.
        Specified by:
        render in interface View
        Parameters:
        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 exchange
        Returns:
        Mono to represent when and if rendering succeeds