Class AbstractMessageConverterMethodArgumentResolver
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
- All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodArgumentResolver
- Direct Known Subclasses:
AbstractMessageConverterMethodProcessor,RequestPartMethodArgumentResolver
public abstract class AbstractMessageConverterMethodArgumentResolver
extends Object
implements org.springframework.web.method.support.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 Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.Logprotected final List<org.springframework.http.converter.HttpMessageConverter<?>> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractMessageConverterMethodArgumentResolver(List<org.springframework.http.converter.HttpMessageConverter<?>> converters) Basic constructor with converters only.AbstractMessageConverterMethodArgumentResolver(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice) Constructor with converters andRequest~andResponseBodyAdvice. -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectadaptArgumentIfNecessary(Object arg, org.springframework.core.MethodParameter parameter) Adapt the given argument against the method parameter, if necessary.protected org.springframework.http.server.ServletServerHttpRequestcreateInputMessage(org.springframework.web.context.request.NativeWebRequest webRequest) Create a newHttpInputMessagefrom the givenNativeWebRequest.protected org.springframework.core.ResolvableTypegetNestedTypeIfNeeded(org.springframework.core.ResolvableType type) Return the generic type of thereturnType(or of the nested type if it is anHttpEntityor/and anOptional).protected List<org.springframework.http.MediaType>getSupportedMediaTypes(Class<?> clazz) Return the media types supported by all provided message converters sorted by specificity viaMimeTypeUtils.sortBySpecificity(List).protected booleanisBindExceptionRequired(org.springframework.web.bind.WebDataBinder binder, org.springframework.core.MethodParameter parameter) Whether to raise a fatal bind exception on validation errors.protected <T> ObjectreadWithMessageConverters(org.springframework.http.HttpInputMessage inputMessage, org.springframework.core.MethodParameter parameter, Type targetType) Create the method argument value of the expected parameter type by reading from the given HttpInputMessage.protected ObjectreadWithMessageConverters(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.protected voidvalidateIfApplicable(org.springframework.web.bind.WebDataBinder binder, org.springframework.core.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, waitMethods inherited from interface org.springframework.web.method.support.HandlerMethodArgumentResolver
resolveArgument, supportsParameter
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger -
messageConverters
-
-
Constructor Details
-
AbstractMessageConverterMethodArgumentResolver
public AbstractMessageConverterMethodArgumentResolver(List<org.springframework.http.converter.HttpMessageConverter<?>> converters) Basic constructor with converters only. -
AbstractMessageConverterMethodArgumentResolver
public AbstractMessageConverterMethodArgumentResolver(List<org.springframework.http.converter.HttpMessageConverter<?>> converters, @Nullable List<Object> requestResponseBodyAdvice) Constructor with converters andRequest~andResponseBodyAdvice.- Since:
- 4.2
-
-
Method Details
-
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 Create the method argument value of the expected parameter type by reading from the given request.- 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 failsorg.springframework.web.HttpMediaTypeNotSupportedException- if no suitable message converter is foundorg.springframework.http.converter.HttpMessageNotReadableException
-
readWithMessageConverters
@Nullable protected <T> Object readWithMessageConverters(org.springframework.http.HttpInputMessage inputMessage, org.springframework.core.MethodParameter parameter, Type targetType) throws IOException, org.springframework.web.HttpMediaTypeNotSupportedException, org.springframework.http.converter.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 descriptortargetType- the target type, not necessarily the same as the method parameter type, for example, forHttpEntity<String>.- Returns:
- the created method argument value
- Throws:
IOException- if the reading from the request failsorg.springframework.web.HttpMediaTypeNotSupportedException- if no suitable message converter is foundorg.springframework.http.converter.HttpMessageNotReadableException
-
getNestedTypeIfNeeded
protected org.springframework.core.ResolvableType getNestedTypeIfNeeded(org.springframework.core.ResolvableType type) Return the generic type of thereturnType(or of the nested type if it is anHttpEntityor/and anOptional). -
createInputMessage
protected org.springframework.http.server.ServletServerHttpRequest createInputMessage(org.springframework.web.context.request.NativeWebRequest webRequest) Create a newHttpInputMessagefrom the givenNativeWebRequest.- Parameters:
webRequest- the web request to create an input message from- Returns:
- the input message
-
validateIfApplicable
protected void validateIfApplicable(org.springframework.web.bind.WebDataBinder binder, org.springframework.core.MethodParameter parameter) Validate 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 usedparameter- the method parameter descriptor- Since:
- 4.1.5
- See Also:
-
isBindExceptionRequired
protected boolean isBindExceptionRequired(org.springframework.web.bind.WebDataBinder binder, org.springframework.core.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:
trueif the next method argument is not of typeErrors- Since:
- 4.1.5
-
getSupportedMediaTypes
Return the media types supported by all provided message converters sorted by specificity viaMimeTypeUtils.sortBySpecificity(List).- Since:
- 5.3.4
-
adaptArgumentIfNecessary
@Nullable protected Object adaptArgumentIfNecessary(@Nullable Object arg, org.springframework.core.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
-