Interface ServerResponse.BodyBuilder
- All Superinterfaces:
- ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
- Enclosing interface:
- ServerResponse
public static interface ServerResponse.BodyBuilder
extends ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
Defines a builder that adds a body to the response.
- 
Method SummaryModifier and TypeMethodDescriptionreactor.core.publisher.Mono<ServerResponse>Variant ofbody(Publisher, Class)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.reactor.core.publisher.Mono<ServerResponse>body(Object producer, ParameterizedTypeReference<?> elementTypeRef) Variant ofbody(Publisher, ParameterizedTypeReference)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.reactor.core.publisher.Mono<ServerResponse>body(BodyInserter<?, ? super ServerHttpResponse> inserter) Set the body of the response to the givenBodyInserterand return it.<T,P extends Publisher<T>> 
 reactor.core.publisher.Mono<ServerResponse>Set the body from the givenPublisher.<T,P extends Publisher<T>> 
 reactor.core.publisher.Mono<ServerResponse>body(P publisher, ParameterizedTypeReference<T> elementTypeRef) Variant ofbody(Publisher, Class)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.reactor.core.publisher.Mono<ServerResponse>Set the body of the response to the givenObjectand return it.<T> reactor.core.publisher.Mono<ServerResponse>bodyValue(T body, ParameterizedTypeReference<T> bodyType) Set the body of the response to the givenObjectand return it.contentLength(long contentLength) Set the length of the body in bytes, as specified by theContent-Lengthheader.contentType(MediaType contentType) Set the media type of the body, as specified by theContent-Typeheader.Add a serialization hint likeJackson2CodecSupport.JSON_VIEW_HINTto customize how the body will be serialized.Customize the serialization hints with the given consumer.reactor.core.publisher.Mono<ServerResponse>Render the template with the givennameusing the givenmodelAttributes.reactor.core.publisher.Mono<ServerResponse>Render the template with the givennameusing the givenmodel.Methods inherited from interface org.springframework.web.reactive.function.server.ServerResponse.HeadersBuilderallow, allow, build, build, build, cacheControl, cookie, cookies, eTag, header, headers, lastModified, lastModified, location, varyBy
- 
Method Details- 
contentLengthSet the length of the body in bytes, as specified by theContent-Lengthheader.- Parameters:
- contentLength- the content length
- Returns:
- this builder
- See Also:
 
- 
contentTypeSet the media type of the body, as specified by theContent-Typeheader.- Parameters:
- contentType- the content type
- Returns:
- this builder
- See Also:
 
- 
hintAdd a serialization hint likeJackson2CodecSupport.JSON_VIEW_HINTto customize how the body will be serialized.- Parameters:
- key- the hint key
- value- the hint value
 
- 
hintsCustomize the serialization hints with the given consumer.- Parameters:
- hintsConsumer- a function that consumes the hints
- Returns:
- this builder
- Since:
- 5.1.6
 
- 
bodyValueSet the body of the response to the givenObjectand return it. This is a shortcut for using abody(BodyInserter)with a value inserter.- Parameters:
- body- the body of the response
- Returns:
- the built response
- Throws:
- IllegalArgumentException- if- bodyis a- Publisheror producer known to- ReactiveAdapterRegistry
- Since:
- 5.2
 
- 
bodyValue<T> reactor.core.publisher.Mono<ServerResponse> bodyValue(T body, ParameterizedTypeReference<T> bodyType) Set the body of the response to the givenObjectand return it. This is a shortcut for using abody(BodyInserter)with a value inserter.- Type Parameters:
- T- the type of the body
- Parameters:
- body- the body of the response
- bodyType- the type of the body, used to capture the generic type
- Returns:
- the built response
- Throws:
- IllegalArgumentException- if- bodyis a- Publisheror producer known to- ReactiveAdapterRegistry
- Since:
- 6.2
 
- 
body<T,P extends Publisher<T>> reactor.core.publisher.Mono<ServerResponse> body(P publisher, Class<T> elementClass) - Type Parameters:
- T- the type of the elements contained in the publisher
- P- the type of the- Publisher
- Parameters:
- publisher- the- Publisherto write to the response
- elementClass- the type of elements published
- Returns:
- the built response
 
- 
body<T,P extends Publisher<T>> reactor.core.publisher.Mono<ServerResponse> body(P publisher, ParameterizedTypeReference<T> elementTypeRef) Variant ofbody(Publisher, Class)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.- Type Parameters:
- T- the type of the elements contained in the publisher
- P- the type of the- Publisher
- Parameters:
- publisher- the- Publisherto use to write the response
- elementTypeRef- the type of elements produced
- Returns:
- the built response
 
- 
bodyVariant ofbody(Publisher, Class)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.- Parameters:
- producer- the producer to write to the request
- elementClass- the type of elements produced
- Returns:
- the built response
- Since:
- 5.2
 
- 
bodyreactor.core.publisher.Mono<ServerResponse> body(Object producer, ParameterizedTypeReference<?> elementTypeRef) Variant ofbody(Publisher, ParameterizedTypeReference)that allows using any producer that can be resolved toPublisherviaReactiveAdapterRegistry.- Parameters:
- producer- the producer to write to the response
- elementTypeRef- the type of elements produced
- Returns:
- the built response
- Since:
- 5.2
 
- 
bodyreactor.core.publisher.Mono<ServerResponse> body(BodyInserter<?, ? super ServerHttpResponse> inserter) Set the body of the response to the givenBodyInserterand return it.- Parameters:
- inserter- the- BodyInserterthat writes to the response
- Returns:
- the built response
 
- 
renderRender the template with the givennameusing the givenmodelAttributes. The model attributes are mapped under a generated name.Note: Empty Collectionsare not added to the model when using this method because we cannot correctly determine the true convention name.- Parameters:
- name- the name of the template to be rendered
- modelAttributes- the modelAttributes used to render the template
- Returns:
- the built response
 
- 
renderRender the template with the givennameusing the givenmodel.- Parameters:
- name- the name of the template to be rendered
- model- the model used to render the template
- Returns:
- the built response
 
 
-