public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter
RequestBodyAdvice
implementation that adds support for Jackson's
@JsonView
annotation declared on a Spring MVC @HttpEntity
or @RequestBody
method parameter.
The deserialization view specified in the annotation will be passed in to the
MappingJackson2HttpMessageConverter
which will then use it to deserialize the request body with.
Note that despite @JsonView
allowing for more than one class to
be specified, the use for a request body advice is only supported with
exactly one class argument. Consider the use of a composite interface.
JsonView
,
ObjectMapper.readerWithView(Class)
Constructor and Description |
---|
JsonViewRequestBodyAdvice() |
Modifier and Type | Method and Description |
---|---|
HttpInputMessage |
beforeBodyRead(HttpInputMessage inputMessage,
MethodParameter methodParameter,
java.lang.reflect.Type targetType,
java.lang.Class<? extends HttpMessageConverter<?>> selectedConverterType)
The default implementation returns the InputMessage that was passed in.
|
boolean |
supports(MethodParameter methodParameter,
java.lang.reflect.Type targetType,
java.lang.Class<? extends HttpMessageConverter<?>> converterType)
Invoked first to determine if this interceptor applies.
|
afterBodyRead, handleEmptyBody
public boolean supports(MethodParameter methodParameter, java.lang.reflect.Type targetType, java.lang.Class<? extends HttpMessageConverter<?>> converterType)
RequestBodyAdvice
methodParameter
- the method parametertargetType
- the target type, not necessarily the same as the method
parameter type, e.g. for HttpEntity<String>
.converterType
- the selected converter typepublic HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter, java.lang.reflect.Type targetType, java.lang.Class<? extends HttpMessageConverter<?>> selectedConverterType) throws java.io.IOException
RequestBodyAdviceAdapter
beforeBodyRead
in interface RequestBodyAdvice
beforeBodyRead
in class RequestBodyAdviceAdapter
inputMessage
- the requestmethodParameter
- the target method parametertargetType
- the target type, not necessarily the same as the method
parameter type, e.g. for HttpEntity<String>
.selectedConverterType
- the converter used to deserialize the bodynull
java.io.IOException