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 with 
HttpMessageConverters.- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static enum
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.Logprotected final List<HttpMessageConverter<?>> 
- 
Constructor SummaryConstructorsConstructorDescriptionAbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters) Basic constructor with converters only.AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters, @Nullable List<Object> requestResponseBodyAdvice) Constructor with converters andRequest~andResponseBodyAdvice.
- 
Method SummaryModifier and TypeMethodDescriptionadaptArgumentIfNecessary(@Nullable Object arg, MethodParameter parameter) Adapt the given argument against the method parameter, if necessary.protected ServletServerHttpRequestcreateInputMessage(NativeWebRequest webRequest) Create a newHttpInputMessagefrom the givenNativeWebRequest.protected ResolvableTypeReturn the generic type of thereturnType(or of the nested type if it is anHttpEntityor/and anOptional).getSupportedMediaTypes(Class<?> clazz) Return the media types supported by all provided message converters sorted by specificity viaMimeTypeUtils.sortBySpecificity(List).protected booleanisBindExceptionRequired(WebDataBinder binder, MethodParameter parameter) Whether to raise a fatal bind exception on validation errors.readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType) Create the method argument value of the expected parameter type by reading from the given HttpInputMessage.readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType) Create the method argument value of the expected parameter type by reading from the given request.protected voidvalidateIfApplicable(WebDataBinder binder, MethodParameter parameter) Validate the binding target if applicable.Methods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerMethodArgumentResolverresolveArgument, supportsParameter
- 
Field Details- 
loggerprotected final org.apache.commons.logging.Log logger
- 
messageConverters
 
- 
- 
Constructor Details- 
AbstractMessageConverterMethodArgumentResolverBasic constructor with converters only.
- 
AbstractMessageConverterMethodArgumentResolverpublic AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters, @Nullable List<Object> requestResponseBodyAdvice) Constructor with converters andRequest~andResponseBodyAdvice.- Since:
- 4.2
 
 
- 
- 
Method Details- 
readWithMessageConvertersprotected @Nullable 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.- 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
- HttpMediaTypeNotSupportedException- if no suitable message converter is found
- HttpMessageNotReadableException
 
- 
readWithMessageConvertersprotected <T> @Nullable 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 request
- parameter- the method parameter descriptor
- targetType- the target type, not necessarily the same as the method parameter type, for example, for- HttpEntity<String>.
- Returns:
- the created method argument value
- Throws:
- IOException- if the reading from the request fails
- HttpMediaTypeNotSupportedException- if no suitable message converter is found
- HttpMessageNotReadableException
 
- 
getNestedTypeIfNeededReturn the generic type of thereturnType(or of the nested type if it is anHttpEntityor/and anOptional).
- 
createInputMessageCreate a newHttpInputMessagefrom the givenNativeWebRequest.- Parameters:
- webRequest- the web request to create an input message from
- Returns:
- the input message
 
- 
validateIfApplicableValidate the binding target if applicable.The default implementation checks for @jakarta.validation.Valid, Spring'sValidated, and custom annotations whose name starts with "Valid".- Parameters:
- binder- the DataBinder to be used
- parameter- the method parameter descriptor
- Since:
- 4.1.5
- See Also:
 
- 
isBindExceptionRequiredWhether to raise a fatal bind exception on validation errors.- Parameters:
- binder- the data binder used to perform data binding
- parameter- the method parameter descriptor
- Returns:
- trueif the next method argument is not of type- Errors
- Since:
- 4.1.5
 
- 
getSupportedMediaTypesReturn the media types supported by all provided message converters sorted by specificity viaMimeTypeUtils.sortBySpecificity(List).- Since:
- 5.3.4
 
- 
adaptArgumentIfNecessaryprotected @Nullable Object adaptArgumentIfNecessary(@Nullable Object arg, MethodParameter parameter) Adapt the given argument against the method parameter, if necessary.- Parameters:
- arg- the resolved argument
- parameter- the method parameter descriptor
- Returns:
- the adapted argument, or the original resolved argument as-is
- Since:
- 4.3.5
 
 
-