Class RequestBodyAdviceAdapter
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter
- All Implemented Interfaces:
RequestBodyAdvice
- Direct Known Subclasses:
JsonViewRequestBodyAdvice, KotlinRequestBodyAdvice
A convenient starting point for implementing
RequestBodyAdvice with default method implementations.
Subclasses are required to implement RequestBodyAdvice.supports(MethodParameter, Type, Class) to return true
depending on when the advice applies.
- Since:
- 4.2
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionafterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) The default implementation returns the body that was passed in.beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) The default implementation returns the InputMessage that was passed in.handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) The default implementation returns the body that was passed in.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RequestBodyAdvice
determineReadHints, supports
-
Constructor Details
-
RequestBodyAdviceAdapter
public RequestBodyAdviceAdapter()
-
-
Method Details
-
beforeBodyRead
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException The default implementation returns the InputMessage that was passed in.- Specified by:
beforeBodyReadin interfaceRequestBodyAdvice- 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
-
afterBodyRead
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) The default implementation returns the body that was passed in.- Specified by:
afterBodyReadin interfaceRequestBodyAdvice- 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
public @Nullable Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) The default implementation returns the body that was passed in.- Specified by:
handleEmptyBodyin interfaceRequestBodyAdvice- 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
-