Top Description Inners Methods
org.springframework.web.servlet.function

public Interface EntityResponse<T>

extends ServerResponse
Known Direct Implementers
org.springframework.web.servlet.function.DefaultEntityResponseBuilder.DefaultEntityResponse
Type Parameters
<T>
the entity type
Imports
java.net.URI, java.time.Instant, .ZonedDateTime, java.util.Set, java.util.function.Consumer, jakarta.servlet.http.Cookie, org.springframework.core.ParameterizedTypeReference, org.springframework.http.CacheControl, .HttpHeaders, .HttpMethod, .HttpStatusCode, .MediaType, org.springframework.util.MultiValueMap

Entity-specific subtype of ServerResponse that exposes entity data.
Author
Arjen Poutsma
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
EntityResponse.Builder<
the entity type
T
>

Defines a builder for EntityResponse.

Method Summary

Modifier and TypeMethod and Description
public T
entity()

Return the entity that makes up this response.

public static <
the type of element contained in the entity
T
>
EntityResponse.Builder<T>

Returns:

the created builder
fromObject
(T
the object that represents the body of the response
t
)

Create a builder with the given object.

public static <
the type of element contained in the entity
T
>
EntityResponse.Builder<T>

Returns:

the created builder
fromObject
(T
the object that represents the body of the response
t
,
ParameterizedTypeReference<T>
the type of the entity, used to capture the generic type
entityType
)

Create a builder with the given object and type reference.

Inherited from org.springframework.web.servlet.function.ServerResponse:
acceptedasyncasyncbadRequestcookiescreatedfromfromheadersnoContentnotFoundokpermanentRedirectrawStatusCodeseeOtherssessestatusstatusstatusCodetemporaryRedirectunprocessableEntitywriteTo

Method Detail

entityback to summary
public T entity()

Return the entity that makes up this response.

fromObjectback to summary
public static <T> EntityResponse.Builder<T> fromObject(T t)

Create a builder with the given object.

Parameters
<T>
the type of element contained in the entity
t:T

the object that represents the body of the response

Returns:EntityResponse.Builder<T>

the created builder

fromObjectback to summary
public static <T> EntityResponse.Builder<T> fromObject(T t, ParameterizedTypeReference<T> entityType)

Create a builder with the given object and type reference.

Parameters
<T>
the type of element contained in the entity
t:T

the object that represents the body of the response

entityType:ParameterizedTypeReference<T>

the type of the entity, used to capture the generic type

Returns:EntityResponse.Builder<T>

the created builder

org.springframework.web.servlet.function back to summary

public Interface EntityResponse.Builder<T>

Known Direct Implementers
org.springframework.web.servlet.function.DefaultEntityResponseBuilder
Type Parameters
<T>
the entity type

Defines a builder for EntityResponse.

Method Summary

Modifier and TypeMethod and Description
public EntityResponse.Builder<T>

Returns:

this builder
allow
(HttpMethod...
the allowed methods
allowedMethods
)

Set the set of allowed HTTP methods, as specified by the Allow header.

public EntityResponse.Builder<T>

Returns:

this builder
allow
(Set<HttpMethod>
the allowed methods
allowedMethods
)

Set the set of allowed HTTP methods, as specified by the Allow header.

public EntityResponse<T>

Returns:

the built response
build
()

Build the response.

public EntityResponse.Builder<T>

Returns:

this builder
cacheControl
(CacheControl
a builder for cache-related HTTP response headers
cacheControl
)

Set the caching directives for the resource, as specified by the HTTP 1.1 Cache-Control header.

public EntityResponse.Builder<T>

Returns:

this builder
contentLength
(long
the content length
contentLength
)

Set the length of the body in bytes, as specified by the Content-Length header.

public EntityResponse.Builder<T>

Returns:

this builder
contentType
(MediaType
the content type
contentType
)

Set the media type of the body, as specified by the Content-Type header.

public EntityResponse.Builder<T>

Returns:

this builder
cookie
(Cookie
the cookie to add
cookie
)

Add the given cookie to the response.

public EntityResponse.Builder<T>

Returns:

this builder
cookies
(Consumer<MultiValueMap<String, Cookie>>
a function that consumes the cookies
cookiesConsumer
)

Manipulate this response's cookies with the given consumer.

public EntityResponse.Builder<T>

Returns:

this builder
eTag
(String
the new entity tag
etag
)

Set the entity tag of the body, as specified by the ETag header.

public EntityResponse.Builder<T>

Returns:

this builder
header
(String
the header name
headerName
,
String...
the header value(s)
headerValues
)

Add the given header value(s) under the given name.

public EntityResponse.Builder<T>

Returns:

this builder
headers
(Consumer<HttpHeaders>
a function that consumes the HttpHeaders
headersConsumer
)

Manipulate this response's headers with the given consumer.

public EntityResponse.Builder<T>

Returns:

this builder
lastModified
(ZonedDateTime
the last modified date
lastModified
)

Set the time the resource was last changed, as specified by the Last-Modified header.

public EntityResponse.Builder<T>

Returns:

this builder
lastModified
(Instant
the last modified date
lastModified
)

Set the time the resource was last changed, as specified by the Last-Modified header.

public EntityResponse.Builder<T>

Returns:

this builder
location
(URI
the location
location
)

Set the location of a resource, as specified by the Location header.

public EntityResponse.Builder<T>

Returns:

this builder
status
(HttpStatusCode
the response status
status
)

Set the HTTP status.

public EntityResponse.Builder<T>

Returns:

this builder
status
(int
the response status
status
)

Set the HTTP status.

public EntityResponse.Builder<T>

Returns:

this builder
varyBy
(String...
request header names
requestHeaders
)

Configure one or more request header names (e.g. "Accept-Language") to add to the "Vary" response header to inform clients that the response is subject to content negotiation and variances based on the value of the given request headers.

Method Detail

allowback to summary
public EntityResponse.Builder<T> allow(HttpMethod... allowedMethods)

Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters
allowedMethods:HttpMethod[]

the allowed methods

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setAllow(Set)
allowback to summary
public EntityResponse.Builder<T> allow(Set<HttpMethod> allowedMethods)

Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters
allowedMethods:Set<HttpMethod>

the allowed methods

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setAllow(Set)
buildback to summary
public EntityResponse<T> build()

Build the response.

Returns:EntityResponse<T>

the built response

cacheControlback to summary
public EntityResponse.Builder<T> cacheControl(CacheControl cacheControl)

Set the caching directives for the resource, as specified by the HTTP 1.1 Cache-Control header.

A CacheControl instance can be built like CacheControl.maxAge(3600).cachePublic().noTransform().

Parameters
cacheControl:CacheControl

a builder for cache-related HTTP response headers

Returns:EntityResponse.Builder<T>

this builder

See Also
RFC-7234 Section 5.2
contentLengthback to summary
public EntityResponse.Builder<T> contentLength(long contentLength)

Set the length of the body in bytes, as specified by the Content-Length header.

Parameters
contentLength:long

the content length

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setContentLength(long)
contentTypeback to summary
public EntityResponse.Builder<T> contentType(MediaType contentType)

Set the media type of the body, as specified by the Content-Type header.

Parameters
contentType:MediaType

the content type

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setContentType(MediaType)
cookieback to summary
public EntityResponse.Builder<T> cookie(Cookie cookie)

Add the given cookie to the response.

Parameters
cookie:Cookie

the cookie to add

Returns:EntityResponse.Builder<T>

this builder

cookiesback to summary
public EntityResponse.Builder<T> cookies(Consumer<MultiValueMap<String, Cookie>> cookiesConsumer)

Manipulate this response's cookies with the given consumer. The cookies provided to the consumer are "live", so that the consumer can be used to overwrite existing cookies, remove cookies, or use any of the other MultiValueMap methods.

Parameters
cookiesConsumer:Consumer<MultiValueMap<String, Cookie>>

a function that consumes the cookies

Returns:EntityResponse.Builder<T>

this builder

eTagback to summary
public EntityResponse.Builder<T> eTag(String etag)

Set the entity tag of the body, as specified by the ETag header.

Parameters
etag:String

the new entity tag

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setETag(String)
headerback to summary
public EntityResponse.Builder<T> header(String headerName, String... headerValues)

Add the given header value(s) under the given name.

Parameters
headerName:String

the header name

headerValues:String[]

the header value(s)

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#add(String, String)
headersback to summary
public EntityResponse.Builder<T> headers(Consumer<HttpHeaders> headersConsumer)

Manipulate this response's headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the other HttpHeaders methods.

Parameters
headersConsumer:Consumer<HttpHeaders>

a function that consumes the HttpHeaders

Returns:EntityResponse.Builder<T>

this builder

lastModifiedback to summary
public EntityResponse.Builder<T> lastModified(ZonedDateTime lastModified)

Set the time the resource was last changed, as specified by the Last-Modified header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
lastModified:ZonedDateTime

the last modified date

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setLastModified(long)
lastModifiedback to summary
public EntityResponse.Builder<T> lastModified(Instant lastModified)

Set the time the resource was last changed, as specified by the Last-Modified header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
lastModified:Instant

the last modified date

Returns:EntityResponse.Builder<T>

this builder

Since
5.1.4
See Also
HttpHeaders#setLastModified(long)
locationback to summary
public EntityResponse.Builder<T> location(URI location)

Set the location of a resource, as specified by the Location header.

Parameters
location:URI

the location

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setLocation(URI)
statusback to summary
public EntityResponse.Builder<T> status(HttpStatusCode status)

Set the HTTP status.

Parameters
status:HttpStatusCode

the response status

Returns:EntityResponse.Builder<T>

this builder

statusback to summary
public EntityResponse.Builder<T> status(int status)

Set the HTTP status.

Parameters
status:int

the response status

Returns:EntityResponse.Builder<T>

this builder

varyByback to summary
public EntityResponse.Builder<T> varyBy(String... requestHeaders)

Configure one or more request header names (e.g. "Accept-Language") to add to the "Vary" response header to inform clients that the response is subject to content negotiation and variances based on the value of the given request headers. The configured request header names are added only if not already present in the response "Vary" header.

Parameters
requestHeaders:String[]

request header names

Returns:EntityResponse.Builder<T>

this builder