Package org.springframework.web.servlet.mvc.method.annotation

# Class JsonViewRequestBodyAdvice

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter
org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice

All Implemented Interfaces:
  `RequestBodyAdvice`

public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter
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 `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.

Since:
  4.2
Author:
  Sebastien Deleuze
See Also:
  - `JsonView`
  - `ObjectMapper.readerWithView(Class)`

## Constructor Summary

Constructors
Constructor
Description
`JsonViewRequestBodyAdvice()`

## Method Summary

Modifier and Type
Method
Description
`org.springframework.http.HttpInputMessage`
`beforeBodyRead(org.springframework.http.HttpInputMessage inputMessage, org.springframework.core.MethodParameter methodParameter, Type targetType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType)`
The default implementation returns the InputMessage that was passed in.
`boolean`
`supports(org.springframework.core.MethodParameter methodParameter, Type targetType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)`
Invoked first to determine if this interceptor applies.

### Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter

`afterBodyRead, handleEmptyBody`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### JsonViewRequestBodyAdvice

public JsonViewRequestBodyAdvice()

## Method Details

### supports

public boolean supports(org.springframework.core.MethodParameter methodParameter, Type targetType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)
Description copied from interface: `RequestBodyAdvice`
Invoked first to determine if this interceptor applies.

Parameters:
  `methodParameter` - the method parameter
  `targetType` - the target type, not necessarily the same as the method parameter type, for example, for `HttpEntity<String>`.
  `converterType` - the selected converter type
Returns:
  whether this interceptor should be invoked or not

### beforeBodyRead

public org.springframework.http.HttpInputMessage beforeBodyRead(org.springframework.http.HttpInputMessage inputMessage, org.springframework.core.MethodParameter methodParameter, Type targetType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType) throws IOException
Description copied from class: `RequestBodyAdviceAdapter`
The default implementation returns the InputMessage that was passed in.

Specified by:
  `beforeBodyRead` in interface `RequestBodyAdvice`
Overrides:
  `beforeBodyRead` in class `RequestBodyAdviceAdapter`
Parameters:
  `inputMessage` - the request
  `methodParameter` - the target method parameter
  `targetType` - the target type, not necessarily the same as the method parameter type, for example, for `HttpEntity<String>`.
  `selectedConverterType` - the converter used to deserialize the body
Returns:
  the input request or a new instance (never `null`)
Throws:
  `IOException`