Class AbstractMessageConverterMethodArgumentResolver
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
- All Implemented Interfaces:
HandlerMethodArgumentResolver
- Direct Known Subclasses:
AbstractMessageConverterMethodProcessor
,RequestPartMethodArgumentResolver
public abstract class AbstractMessageConverterMethodArgumentResolver extends Object implements HandlerMethodArgumentResolver
A base class for resolving method argument values by reading from the body of a request withHttpMessageConverter
s.- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
Field Summary
Fields Modifier and Type Field Description protected List<MediaType>
allSupportedMediaTypes
protected Log
logger
protected List<HttpMessageConverter<?>>
messageConverters
Constructor Summary
Constructors Constructor Description AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters)
Basic constructor with converters only.AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)
Constructor with converters andRequest~
andResponseBodyAdvice
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
adaptArgumentIfNecessary(Object arg, MethodParameter parameter)
Adapt the given argument against the method parameter, if necessary.protected ServletServerHttpRequest
createInputMessage(NativeWebRequest webRequest)
Create a newHttpInputMessage
from the givenNativeWebRequest
.protected org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyAdviceChain
getAdvice()
Return the configuredRequestBodyAdvice
andRequestBodyAdvice
where each instance may be wrapped as aControllerAdviceBean
.protected boolean
isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter)
Whether to raise a fatal bind exception on validation errors.protected <T> Object
readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType)
Create the method argument value of the expected parameter type by reading from the given HttpInputMessage.protected <T> Object
readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType)
Create the method argument value of the expected parameter type by reading from the given request.protected void
validateIfApplicable(WebDataBinder binder, MethodParameter parameter)
Validate the binding target if applicable.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.method.support.HandlerMethodArgumentResolver
resolveArgument, supportsParameter
Field Detail
messageConverters
protected final List<HttpMessageConverter<?>> messageConverters
allSupportedMediaTypes
protected final List<MediaType> allSupportedMediaTypes
Constructor Detail
AbstractMessageConverterMethodArgumentResolver
public AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters)
Basic constructor with converters only.
AbstractMessageConverterMethodArgumentResolver
public AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)
Constructor with converters andRequest~
andResponseBodyAdvice
.- Since:
- 4.2
Method Detail
getAdvice
protected org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyAdviceChain getAdvice()
Return the configuredRequestBodyAdvice
andRequestBodyAdvice
where each instance may be wrapped as aControllerAdviceBean
.
readWithMessageConverters
protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException
Create the method argument value of the expected parameter type by reading from the given request.- Type Parameters:
T
- the expected type of the argument value to be created- Parameters:
webRequest
- the current requestparameter
- the method parameter descriptor (may benull
)paramType
- the type of the argument value to be created- Returns:
- the created method argument value
- Throws:
IOException
- if the reading from the request failsHttpMediaTypeNotSupportedException
- if no suitable message converter is foundHttpMessageNotReadableException
readWithMessageConverters
protected <T> Object readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException
Create the method argument value of the expected parameter type by reading from the given HttpInputMessage.- Type Parameters:
T
- the expected type of the argument value to be created- Parameters:
inputMessage
- the HTTP input message representing the current requestparameter
- the method parameter descriptor (may benull
)targetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.- Returns:
- the created method argument value
- Throws:
IOException
- if the reading from the request failsHttpMediaTypeNotSupportedException
- if no suitable message converter is foundHttpMessageNotReadableException
createInputMessage
protected ServletServerHttpRequest createInputMessage(NativeWebRequest webRequest)
Create a newHttpInputMessage
from the givenNativeWebRequest
.- Parameters:
webRequest
- the web request to create an input message from- Returns:
- the input message
validateIfApplicable
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter)
Validate the binding target if applicable.The default implementation checks for
@javax.validation.Valid
, Spring'sValidated
, and custom annotations whose name starts with "Valid".- Parameters:
binder
- the DataBinder to be usedparameter
- the method parameter descriptor- Since:
- 4.1.5
- See Also:
isBindExceptionRequired(org.springframework.web.bind.WebDataBinder, org.springframework.core.MethodParameter)
isBindExceptionRequired
protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter)
Whether to raise a fatal bind exception on validation errors.- Parameters:
binder
- the data binder used to perform data bindingparameter
- the method parameter descriptor- Returns:
true
if the next method argument is not of typeErrors
- Since:
- 4.1.5
adaptArgumentIfNecessary
protected Object adaptArgumentIfNecessary(Object arg, MethodParameter parameter)
Adapt the given argument against the method parameter, if necessary.- Parameters:
arg
- the resolved argumentparameter
- the method parameter descriptor- Returns:
- the adapted argument, or the original resolved argument as-is
- Since:
- 4.3.5