Top Description Methods
org.springframework.web.servlet.mvc.method.annotation

public Interface RequestBodyAdvice

Known Direct Implementers
org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter, org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyAdviceChain
Imports
java.io.IOException, java.lang.reflect.Type, org.springframework.core.MethodParameter, org.springframework.http.HttpInputMessage, org.springframework.http.converter.HttpMessageConverter, org.springframework.lang.Nullable

Allows customizing the request before its body is read and converted into an Object and also allows for processing of the resulting Object before it is passed into a controller method as an @RequestBody or an HttpEntity method argument.

Implementations of this contract may be registered directly with the RequestMappingHandlerAdapter or more likely annotated with @ControllerAdvice in which case they are auto-detected.

Author
Rossen Stoyanchev
Since
4.2

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the same body or a new instance
afterBodyRead
(Object
set to the converter Object before the first advice is called
body
,
HttpInputMessage
the request
inputMessage
,
MethodParameter
the target method parameter
parameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the converter used to deserialize the body
converterType
)

Invoked third (and last) after the request body is converted to an Object.

public HttpInputMessage

Returns:

the input request or a new instance (never null)
beforeBodyRead
(HttpInputMessage
the request
inputMessage
,
MethodParameter
the target method parameter
parameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the converter used to deserialize the body
converterType
)

Invoked second before the request body is read and converted.

public Object

Returns:

the value to use, or null which may then raise an HttpMessageNotReadableException if the argument is required
handleEmptyBody
(Object
usually set to null before the first advice is called
body
,
HttpInputMessage
the request
inputMessage
,
MethodParameter
the method parameter
parameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Invoked second (and last) if the body is empty.

public boolean

Returns:

whether this interceptor should be invoked or not
supports
(MethodParameter
the method parameter
methodParameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Invoked first to determine if this interceptor applies.

Method Detail

afterBodyReadback to summary
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)

Invoked third (and last) after the request body is converted to an Object.

Parameters
body:Object

set to the converter Object before the first advice is called

inputMessage:HttpInputMessage

the request

parameter:MethodParameter

the target method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the converter used to deserialize the body

Returns:Object

the same body or a new instance

beforeBodyReadback to summary
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException

Invoked second before the request body is read and converted.

Parameters
inputMessage:HttpInputMessage

the request

parameter:MethodParameter

the target method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the converter used to deserialize the body

Returns:HttpInputMessage

the input request or a new instance (never null)

handleEmptyBodyback to summary
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)

Invoked second (and last) if the body is empty.

Parameters
body:Object

usually set to null before the first advice is called

inputMessage:HttpInputMessage

the request

parameter:MethodParameter

the method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:Object

the value to use, or null which may then raise an HttpMessageNotReadableException if the argument is required

Annotations
@Nullable
supportsback to summary
public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)

Invoked first to determine if this interceptor applies.

Parameters
methodParameter:MethodParameter

the method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:boolean

whether this interceptor should be invoked or not