Class RequestBodyAdviceAdapter
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter
- All Implemented Interfaces:
RequestBodyAdvice
- Direct Known Subclasses:
JsonViewRequestBodyAdvice
public abstract class RequestBodyAdviceAdapter extends Object implements RequestBodyAdvice
A convenient starting point for implementingResponseBodyAdvice
with default method implementations.Sub-classes are required to implement
RequestBodyAdvice.supports(org.springframework.core.MethodParameter, java.lang.reflect.Type, java.lang.Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>)
to return true depending on when the advice applies.- Since:
- 4.2
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description RequestBodyAdviceAdapter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
The default implementation returns the body that was passed in.HttpInputMessage
beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
The default implementation returns the InputMessage that was passed in.Object
handleEmptyBody(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice
supports
Constructor Detail
RequestBodyAdviceAdapter
public RequestBodyAdviceAdapter()
Method Detail
handleEmptyBody
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
The default implementation returns the body that was passed in.- Specified by:
handleEmptyBody
in interfaceRequestBodyAdvice
- Parameters:
body
- set tonull
before the first advice is calledinputMessage
- the requestparameter
- the method parametertargetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.converterType
- the selected converter type- Returns:
- the value to use or
null
which may then raise anHttpMessageNotReadableException
if the argument is required.
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:
beforeBodyRead
in interfaceRequestBodyAdvice
- Parameters:
inputMessage
- the requestparameter
- the target method parametertargetType
- the target type, not necessarily the same as the method parameter type, e.g. 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:
afterBodyRead
in interfaceRequestBodyAdvice
- Parameters:
body
- set to the converter Object before the 1st advice is calledinputMessage
- the requestparameter
- the target method parametertargetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.converterType
- the converter used to deserialize the body- Returns:
- the same body or a new instance