Top Description Inners Fields Constructors Methods
org.springframework.web.method.annotation

public abstract Class AbstractNamedValueMethodArgumentResolver

extends Object
implements HandlerMethodArgumentResolver
Class Inheritance
All Implemented Interfaces
org.springframework.web.method.support.HandlerMethodArgumentResolver
Known Direct Subclasses
org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver, org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver, org.springframework.web.method.annotation.RequestParamMethodArgumentResolver, org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver
Imports
java.lang.reflect.Method, java.util.Map, .Objects, java.util.concurrent.ConcurrentHashMap, jakarta.servlet.ServletException, kotlin.reflect.KFunction, kotlin.reflect.KParameter, kotlin.reflect.jvm.ReflectJvmMapping, org.springframework.beans.ConversionNotSupportedException, .TypeMismatchException, org.springframework.beans.factory.config.BeanExpressionContext, .BeanExpressionResolver, .ConfigurableBeanFactory, org.springframework.core.KotlinDetector, .MethodParameter, org.springframework.lang.Nullable, org.springframework.web.bind.ServletRequestBindingException, .WebDataBinder, org.springframework.web.bind.annotation.ValueConstants, org.springframework.web.bind.support.WebDataBinderFactory, org.springframework.web.context.request.NativeWebRequest, .RequestScope, org.springframework.web.method.support.HandlerMethodArgumentResolver, .ModelAndViewContainer

Abstract base class for resolving method arguments from a named value. Request parameters, request headers, and path variables are examples of named values. Each may have a name, a required flag, and a default value.

Subclasses define how to do the following:

A default value string can contain ${...} placeholders and Spring Expression Language #{...} expressions. For this to work a ConfigurableBeanFactory must be supplied to the class constructor.

A WebDataBinder is created to apply type conversion to the resolved argument value if it doesn't match the method parameter type.

Authors
Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
Since
3.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AbstractNamedValueMethodArgumentResolver.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

protected static class
AbstractNamedValueMethodArgumentResolver.NamedValueInfo

Represents the information about a named value, including name, whether it's required and a default value.

Field Summary

Modifier and TypeField and Description
private final ConfigurableBeanFactory
private final BeanExpressionContext
private final Map<MethodParameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo>

Constructor Summary

AccessConstructor and Description
public
public
AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory
a bean factory to use for resolving ${...} placeholder and #{...} SpEL expressions in default values, or null if default values are not expected to contain expressions
beanFactory
)

Create a new AbstractNamedValueMethodArgumentResolver instance.

Method Summary

Modifier and TypeMethod and Description
private static Object
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo

Returns:

the named value information
createNamedValueInfo
(MethodParameter
the method parameter
parameter
)

Create the NamedValueInfo object for the given method parameter.

private AbstractNamedValueMethodArgumentResolver.NamedValueInfo
getNamedValueInfo(MethodParameter parameter)

Obtain the named value for the given method parameter.

protected void
handleMissingValue(String
the name for the value
name
,
MethodParameter
the method parameter
parameter
,
NativeWebRequest
the current request
request
)

Invoked when a named value is required, but resolveName(String, MethodParameter, NativeWebRequest) returned null and there is no default value.

protected void
handleMissingValue(String
the name for the value
name
,
MethodParameter
the method parameter
parameter
)

Invoked when a named value is required, but resolveName(String, MethodParameter, NativeWebRequest) returned null and there is no default value.

protected void
handleMissingValueAfterConversion(String
the name for the value
name
,
MethodParameter
the method parameter
parameter
,
NativeWebRequest
the current request
request
)

Invoked when a named value is present but becomes null after conversion.

private Object
handleNullValue(String name, Object value, Class<?> paramType)

A null results in a false value for booleans or an exception for other primitives.

protected void
handleResolvedValue(Object
the resolved argument value
arg
,
String
the argument name
name
,
MethodParameter
the argument parameter type
parameter
,
ModelAndViewContainer
the ModelAndViewContainer (may be null)
mavContainer
,
NativeWebRequest
the current request
webRequest
)

Invoked after a value is resolved.

public final Object
resolveArgument(MethodParameter
the method parameter to resolve. This parameter must have previously been passed to supportsParameter which must have returned true.
parameter
,
ModelAndViewContainer
the ModelAndViewContainer for the current request
mavContainer
,
NativeWebRequest
the current request
webRequest
,
WebDataBinderFactory
a factory for creating WebDataBinder instances
binderFactory
)

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given request.

private Object
resolveEmbeddedValuesAndExpressions(String value)

Resolve the given annotation-specified value, potentially containing placeholders and expressions.

protected abstract Object

Returns:

the resolved argument (may be null)
resolveName
(String
the name of the value being resolved
name
,
MethodParameter
the method parameter to resolve to an argument value (pre-nested in case of a java.util.Optional declaration)
parameter
,
NativeWebRequest
the current request
request
)

Resolve the given parameter type and value name into an argument value.

private AbstractNamedValueMethodArgumentResolver.NamedValueInfo
updateNamedValueInfo(MethodParameter parameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo info)

Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configurableBeanFactoryback to summary
private final ConfigurableBeanFactory configurableBeanFactory
Annotations
@Nullable
expressionContextback to summary
private final BeanExpressionContext expressionContext
Annotations
@Nullable
namedValueInfoCacheback to summary
private final Map<MethodParameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo> namedValueInfoCache

Constructor Detail

AbstractNamedValueMethodArgumentResolverback to summary
public AbstractNamedValueMethodArgumentResolver()
AbstractNamedValueMethodArgumentResolverback to summary
public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory)

Create a new AbstractNamedValueMethodArgumentResolver instance.

Parameters
beanFactory:ConfigurableBeanFactory

a bean factory to use for resolving ${...} placeholder and #{...} SpEL expressions in default values, or null if default values are not expected to contain expressions

Method Detail

convertIfNecessaryback to summary
private static Object convertIfNecessary(MethodParameter parameter, NativeWebRequest webRequest, WebDataBinderFactory binderFactory, AbstractNamedValueMethodArgumentResolver.NamedValueInfo namedValueInfo, Object arg) throws Exception
Annotations
@Nullable
createNamedValueInfoback to summary
protected abstract AbstractNamedValueMethodArgumentResolver.NamedValueInfo createNamedValueInfo(MethodParameter parameter)

Create the NamedValueInfo object for the given method parameter. Implementations typically retrieve the method annotation by means of MethodParameter#getParameterAnnotation(Class).

Parameters
parameter:MethodParameter

the method parameter

Returns:AbstractNamedValueMethodArgumentResolver.NamedValueInfo

the named value information

getNamedValueInfoback to summary
private AbstractNamedValueMethodArgumentResolver.NamedValueInfo getNamedValueInfo(MethodParameter parameter)

Obtain the named value for the given method parameter.

handleMissingValueback to summary
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception

Invoked when a named value is required, but resolveName(String, MethodParameter, NativeWebRequest) returned null and there is no default value. Subclasses typically throw an exception in this case.

Parameters
name:String

the name for the value

parameter:MethodParameter

the method parameter

request:NativeWebRequest

the current request

Since
4.3
handleMissingValueback to summary
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletException

Invoked when a named value is required, but resolveName(String, MethodParameter, NativeWebRequest) returned null and there is no default value. Subclasses typically throw an exception in this case.

Parameters
name:String

the name for the value

parameter:MethodParameter

the method parameter

handleMissingValueAfterConversionback to summary
protected void handleMissingValueAfterConversion(String name, MethodParameter parameter, NativeWebRequest request) throws Exception

Invoked when a named value is present but becomes null after conversion.

Parameters
name:String

the name for the value

parameter:MethodParameter

the method parameter

request:NativeWebRequest

the current request

Since
5.3.6
handleNullValueback to summary
private Object handleNullValue(String name, Object value, Class<?> paramType)

A null results in a false value for booleans or an exception for other primitives.

Annotations
@Nullable
handleResolvedValueback to summary
protected void handleResolvedValue(Object arg, String name, MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest)

Invoked after a value is resolved.

Parameters
arg:Object

the resolved argument value

name:String

the argument name

parameter:MethodParameter

the argument parameter type

mavContainer:ModelAndViewContainer

the ModelAndViewContainer (may be null)

webRequest:NativeWebRequest

the current request

resolveArgumentback to summary
public final Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given request. A ModelAndViewContainer provides access to the model for the request. A WebDataBinderFactory provides a way to create a WebDataBinder instance when needed for data binding and type conversion purposes.

Parameters
parameter:MethodParameter

the method parameter to resolve. This parameter must have previously been passed to supportsParameter which must have returned true.

mavContainer:ModelAndViewContainer

the ModelAndViewContainer for the current request

webRequest:NativeWebRequest

the current request

binderFactory:WebDataBinderFactory

a factory for creating WebDataBinder instances

Returns:Object

the resolved argument value, or null if not resolvable

Annotations
@Override
@Nullable
Exceptions
Exception:
in case of errors with the preparation of argument values
resolveEmbeddedValuesAndExpressionsback to summary
private Object resolveEmbeddedValuesAndExpressions(String value)

Resolve the given annotation-specified value, potentially containing placeholders and expressions.

Annotations
@Nullable
resolveNameback to summary
protected abstract Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception

Resolve the given parameter type and value name into an argument value.

Parameters
name:String

the name of the value being resolved

parameter:MethodParameter

the method parameter to resolve to an argument value (pre-nested in case of a java.util.Optional declaration)

request:NativeWebRequest

the current request

Returns:Object

the resolved argument (may be null)

Annotations
@Nullable
Exceptions
Exception:
in case of errors
updateNamedValueInfoback to summary
private AbstractNamedValueMethodArgumentResolver.NamedValueInfo updateNamedValueInfo(MethodParameter parameter, AbstractNamedValueMethodArgumentResolver.NamedValueInfo info)

Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.

org.springframework.web.method.annotation back to summary

private Class AbstractNamedValueMethodArgumentResolver.KotlinDelegate

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean
hasDefaultValue(MethodParameter parameter)

Check whether the specified MethodParameter represents a nullable Kotlin type or an optional parameter (with a default value in the Kotlin declaration).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

KotlinDelegateback to summary
private KotlinDelegate()

Method Detail

hasDefaultValueback to summary
public static boolean hasDefaultValue(MethodParameter parameter)

Check whether the specified MethodParameter represents a nullable Kotlin type or an optional parameter (with a default value in the Kotlin declaration).

org.springframework.web.method.annotation back to summary

protected Class AbstractNamedValueMethodArgumentResolver.NamedValueInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.NamedValueInfo
Known Direct Subclasses
org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver.ExpressionValueNamedValueInfo, org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver.RequestHeaderNamedValueInfo, org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.RequestParamNamedValueInfo, org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver.CookieValueNamedValueInfo

Represents the information about a named value, including name, whether it's required and a default value.

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
public
NamedValueInfo(String name, boolean required, String defaultValue)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultValueback to summary
private final String defaultValue
Annotations
@Nullable
nameback to summary
private final String name
requiredback to summary
private final boolean required

Constructor Detail

NamedValueInfoback to summary
public NamedValueInfo(String name, boolean required, String defaultValue)