Top Description Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class JsonViewRequestBodyAdvice

extends RequestBodyAdviceAdapter
Class Inheritance
Imports
java.io.IOException, java.lang.reflect.Type, com.fasterxml.jackson.annotation.JsonView, org.springframework.core.MethodParameter, org.springframework.http.HttpInputMessage, org.springframework.http.converter.HttpMessageConverter, org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter, .MappingJacksonInputMessage, org.springframework.util.Assert

A 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 org.springframework.http.converter.json.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.

Author
Sebastien Deleuze
Since
4.2
See Also
com.fasterxml.jackson.annotation.JsonView, com.fasterxml.jackson.databind.ObjectMapper#readerWithView(Class)

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HttpInputMessage
beforeBodyRead(HttpInputMessage
the request
inputMessage
,
MethodParameter
the target method parameter
methodParameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the converter used to deserialize the body
selectedConverterType
)

Overrides org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter.beforeBodyRead.

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

The default implementation returns the InputMessage that was passed in.

public boolean
supports(MethodParameter
the method parameter
methodParameter
,
Type
the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
targetType
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.supports.

Invoked first to determine if this interceptor applies.

Inherited from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter:
afterBodyReadhandleEmptyBody

Constructor Detail

JsonViewRequestBodyAdviceback to summary
public JsonViewRequestBodyAdvice()

Method Detail

beforeBodyReadback to summary
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException

Overrides org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter.beforeBodyRead.

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter.beforeBodyRead.

The default implementation returns the InputMessage that was passed in.

Parameters
inputMessage:HttpInputMessage

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

the request

methodParameter:MethodParameter

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

the target method parameter

targetType:Type

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

selectedConverterType:Class<? extends HttpMessageConverter<?>>

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

the converter used to deserialize the body

Returns:HttpInputMessage

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.beforeBodyRead.

the input request or a new instance (never null)

Annotations
@Override
supportsback to summary
public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)

Implements org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.supports.

Doc from org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice.supports.

Invoked first to determine if this interceptor applies.

Parameters
methodParameter:MethodParameter

the method parameter

targetType:Type

the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:boolean

whether this interceptor should be invoked or not

Annotations
@Override