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

# Class RequestResponseBodyMethodProcessor

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor

All Implemented Interfaces:
  `org.springframework.web.method.support.HandlerMethodArgumentResolver`, `org.springframework.web.method.support.HandlerMethodReturnValueHandler`

public class RequestResponseBodyMethodProcessor extends AbstractMessageConverterMethodProcessor
Resolves method arguments annotated with `@RequestBody` and handles return values from methods annotated with `@ResponseBody` by reading and writing to the body of the request or response with an `HttpMessageConverter`.

An `@RequestBody` method argument is also validated if it is annotated with any annotations that trigger validation. In case of validation failure, `MethodArgumentNotValidException` is raised and results in an HTTP 400 response status code if `DefaultHandlerExceptionResolver` is configured.

Since:
  3.1
Author:
  Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller

## Nested Class Summary

## Nested classes/interfaces inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver

`AbstractMessageConverterMethodArgumentResolver.ConverterType`

## Field Summary

### Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver

`logger, messageConverters`

## Constructor Summary

Constructors
Constructor
Description
`RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters)`
Basic constructor with converters only.
`RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)`
Complete constructor for resolving `@RequestBody` method arguments.
`RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, org.springframework.web.accept.ContentNegotiationManager manager)`
Basic constructor with converters and `ContentNegotiationManager`.
`RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, org.springframework.web.accept.ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)`
Variant of `RequestResponseBodyMethodProcessor(List, List)` with an additional `ContentNegotiationManager` argument, for return value handling.
`RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, org.springframework.web.accept.ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice, List<org.springframework.web.ErrorResponse.Interceptor> interceptors)`
Variant of`RequestResponseBodyMethodProcessor(List, ContentNegotiationManager, List)` with an additional `ErrorResponse.Interceptor` argument for return value handling.

## Method Summary

Modifier and Type
Method
Description
`protected boolean`
`checkRequired(org.springframework.core.MethodParameter parameter)`
`void`
`handleReturnValue(Object returnValue, org.springframework.core.MethodParameter returnType, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest)`
`protected Object`
`readWithMessageConverters(org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.core.MethodParameter parameter, Type paramType)`
Create the method argument value of the expected parameter type by reading from the given request.
`Object`
`resolveArgument(org.springframework.core.MethodParameter parameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory)`
Throws MethodArgumentNotValidException if validation fails.
`boolean`
`supportsParameter(org.springframework.core.MethodParameter parameter)`
`boolean`
`supportsReturnType(org.springframework.core.MethodParameter returnType)`

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

`createOutputMessage, getProducibleMediaTypes, getProducibleMediaTypes, getReturnValueType, invokeErrorResponseInterceptors, isResourceType, writeWithMessageConverters, writeWithMessageConverters`

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

`adaptArgumentIfNecessary, createInputMessage, getNestedTypeIfNeeded, getSupportedMediaTypes, isBindExceptionRequired, readWithMessageConverters, validateIfApplicable`

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

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

## Constructor Details

### RequestResponseBodyMethodProcessor

public RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters)
Basic constructor with converters only. Suitable for resolving `@RequestBody`. For handling `@ResponseBody` consider also providing a `ContentNegotiationManager`.

### RequestResponseBodyMethodProcessor

public RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable org.springframework.web.accept.ContentNegotiationManager manager)
Basic constructor with converters and `ContentNegotiationManager`. Suitable for resolving `@RequestBody` and handling `@ResponseBody` without `Request~` or `ResponseBodyAdvice`.

### RequestResponseBodyMethodProcessor

public RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable List<Object> requestResponseBodyAdvice)
Complete constructor for resolving `@RequestBody` method arguments. For handling `@ResponseBody` consider also providing a `ContentNegotiationManager`.

Since:
  4.2

### RequestResponseBodyMethodProcessor

public RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable org.springframework.web.accept.ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice)
Variant of `RequestResponseBodyMethodProcessor(List, List)` with an additional `ContentNegotiationManager` argument, for return value handling.

### RequestResponseBodyMethodProcessor

public RequestResponseBodyMethodProcessor(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable org.springframework.web.accept.ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice, List<org.springframework.web.ErrorResponse.Interceptor> interceptors)
Variant of`RequestResponseBodyMethodProcessor(List, ContentNegotiationManager, List)` with an additional `ErrorResponse.Interceptor` argument for return value handling.

Since:
  6.2

## Method Details

### supportsParameter

public boolean supportsParameter(org.springframework.core.MethodParameter parameter)

### supportsReturnType

public boolean supportsReturnType(org.springframework.core.MethodParameter returnType)

### resolveArgument

@Nullable public Object resolveArgument(org.springframework.core.MethodParameter parameter, @Nullable org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, @Nullable org.springframework.web.bind.support.WebDataBinderFactory binderFactory) throws Exception
Throws MethodArgumentNotValidException if validation fails.

Throws:
  `org.springframework.http.converter.HttpMessageNotReadableException` - if `RequestBody.required()` is `true` and there is no body content or if there is no suitable converter to read the content with.
  `Exception`

### readWithMessageConverters

@Nullable protected Object readWithMessageConverters(org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.core.MethodParameter parameter, Type paramType) throws IOException, org.springframework.web.HttpMediaTypeNotSupportedException, org.springframework.http.converter.HttpMessageNotReadableException
Description copied from class: `AbstractMessageConverterMethodArgumentResolver`
Create the method argument value of the expected parameter type by reading from the given request.

Overrides:
  `readWithMessageConverters` in class `AbstractMessageConverterMethodArgumentResolver`
Parameters:
  `webRequest` - the current request
  `parameter` - the method parameter descriptor (may be `null`)
  `paramType` - the type of the argument value to be created
Returns:
  the created method argument value
Throws:
  `IOException` - if the reading from the request fails
  `org.springframework.web.HttpMediaTypeNotSupportedException` - if no suitable message converter is found
  `org.springframework.http.converter.HttpMessageNotReadableException`

### checkRequired

protected boolean checkRequired(org.springframework.core.MethodParameter parameter)

### handleReturnValue

public void handleReturnValue(@Nullable Object returnValue, org.springframework.core.MethodParameter returnType, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest) throws IOException, org.springframework.web.HttpMediaTypeNotAcceptableException, org.springframework.http.converter.HttpMessageNotWritableException

Throws:
  `IOException`
  `org.springframework.web.HttpMediaTypeNotAcceptableException`
  `org.springframework.http.converter.HttpMessageNotWritableException`