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.
Jackson 2.5 or later is required for parameter-level use of @JsonView
.
JsonView
,
ObjectMapper.readerWithView(Class)
Constructor and Description |
---|
JsonViewRequestBodyAdvice() |
Modifier and Type | Method and Description |
---|---|
HttpInputMessage |
beforeBodyRead(HttpInputMessage inputMessage,
MethodParameter methodParameter,
Type targetType,
Class<? extends HttpMessageConverter<?>> selectedConverterType)
The default implementation returns the InputMessage that was passed in.
|
boolean |
supports(MethodParameter methodParameter,
Type targetType,
Class<? extends HttpMessageConverter<?>> converterType)
Invoked first to determine if this interceptor applies.
|
afterBodyRead, handleEmptyBody
public boolean supports(MethodParameter methodParameter, Type targetType, 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, Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws 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
IOException