Interface RequestBodyAdvice
- All Known Implementing Classes:
JsonViewRequestBodyAdvice,RequestBodyAdviceAdapter
public interface RequestBodyAdvice
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.
- Since:
- 4.2
- Author:
- Rossen Stoyanchev, Sebastien Deleuze
-
Method Summary
Modifier and TypeMethodDescriptionafterBodyRead(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.beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) Invoked second before the request body is read and converted.determineReadHints(MethodParameter parameter, Type targetType, Class<? extends SmartHttpMessageConverter<?>> converterType) Invoked to determine read hints if the converter is aSmartHttpMessageConverter.handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) Invoked second (and last) if the body is empty.booleansupports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) Invoked first to determine if this interceptor applies.
-
Method Details
-
supports
boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) Invoked first to determine if this interceptor applies.- Parameters:
methodParameter- the method parametertargetType- the target type, not necessarily the same as the method parameter type, for example, forHttpEntity<String>.converterType- the selected converter type- Returns:
- whether this interceptor should be invoked or not
-
beforeBodyRead
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- the requestparameter- the target method parametertargetType- the target type, not necessarily the same as the method parameter type, for example, forHttpEntity<String>.converterType- the converter used to deserialize the body- Returns:
- the input request or a new instance (never
null) - Throws:
IOException
-
determineReadHints
default @Nullable Map<String,Object> determineReadHints(MethodParameter parameter, Type targetType, Class<? extends SmartHttpMessageConverter<?>> converterType) Invoked to determine read hints if the converter is aSmartHttpMessageConverter.- Parameters:
parameter- the target method parametertargetType- the target type, not necessarily the same as the method parameter type, for example, forHttpEntity<String>.converterType- the selected converter type- Returns:
- the hints determined otherwise
null - Since:
- 7.0
-
afterBodyRead
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- set to the converter Object before the first advice is calledinputMessage- the requestparameter- the target method parametertargetType- the target type, not necessarily the same as the method parameter type, for example, forHttpEntity<String>.converterType- the converter used to deserialize the body- Returns:
- the same body or a new instance
-
handleEmptyBody
@Nullable Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) Invoked second (and last) if the body is empty.- Parameters:
body- usually set tonullbefore the first advice is calledinputMessage- the requestparameter- the method parametertargetType- the target type, not necessarily the same as the method parameter type, for example, forHttpEntity<String>.converterType- the selected converter type- Returns:
- the value to use, or
nullwhich may then raise anHttpMessageNotReadableExceptionif the argument is required
-