public abstract class AbstractMessageConverterMethodArgumentResolver extends Object implements HandlerMethodArgumentResolver
HttpMessageConverters
.Modifier and Type | Field and Description |
---|---|
protected Log |
logger |
protected List<HttpMessageConverter<?>> |
messageConverters |
Constructor and Description |
---|
AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters)
Basic constructor with converters only.
|
AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters,
List<Object> requestResponseBodyAdvice)
Constructor with converters and
Request~ and ResponseBodyAdvice . |
Modifier and Type | Method and 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 new
HttpInputMessage from the given NativeWebRequest . |
protected List<MediaType> |
getSupportedMediaTypes(Class<?> clazz)
Return the media types supported by all provided message converters sorted
by specificity via
MediaType.sortBySpecificity(List) . |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
resolveArgument, supportsParameter
protected final Log logger
protected final List<HttpMessageConverter<?>> messageConverters
public AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters)
public AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters, @Nullable List<Object> requestResponseBodyAdvice)
Request~
and ResponseBodyAdvice
.@Nullable protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException
T
- the expected type of the argument value to be createdwebRequest
- the current requestparameter
- the method parameter descriptor (may be null
)paramType
- the type of the argument value to be createdIOException
- if the reading from the request failsHttpMediaTypeNotSupportedException
- if no suitable message converter is foundHttpMessageNotReadableException
@Nullable protected <T> Object readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException
T
- the expected type of the argument value to be createdinputMessage
- the HTTP input message representing the current requestparameter
- the method parameter descriptortargetType
- the target type, not necessarily the same as the method
parameter type, e.g. for HttpEntity<String>
.IOException
- if the reading from the request failsHttpMediaTypeNotSupportedException
- if no suitable message converter is foundHttpMessageNotReadableException
protected ServletServerHttpRequest createInputMessage(NativeWebRequest webRequest)
HttpInputMessage
from the given NativeWebRequest
.webRequest
- the web request to create an input message fromprotected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter)
The default implementation checks for @javax.validation.Valid
,
Spring's Validated
,
and custom annotations whose name starts with "Valid".
binder
- the DataBinder to be usedparameter
- the method parameter descriptorisBindExceptionRequired(org.springframework.web.bind.WebDataBinder, org.springframework.core.MethodParameter)
protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter)
binder
- the data binder used to perform data bindingparameter
- the method parameter descriptortrue
if the next method argument is not of type Errors
protected List<MediaType> getSupportedMediaTypes(Class<?> clazz)
MediaType.sortBySpecificity(List)
.@Nullable protected Object adaptArgumentIfNecessary(@Nullable Object arg, MethodParameter parameter)
arg
- the resolved argumentparameter
- the method parameter descriptor