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

public abstract Class AbstractNamedValueArgumentResolver

extends HandlerMethodArgumentResolverSupport
Class Inheritance
Known Direct Subclasses
org.springframework.web.reactive.result.method.annotation.AbstractNamedValueSyncArgumentResolver, org.springframework.web.reactive.result.method.annotation.SessionAttributeMethodArgumentResolver
Imports
java.lang.reflect.Method, java.util.Map, .Objects, java.util.concurrent.ConcurrentHashMap, kotlin.reflect.KFunction, kotlin.reflect.KParameter, kotlin.reflect.jvm.ReflectJvmMapping, reactor.core.publisher.Mono, org.springframework.beans.ConversionNotSupportedException, .TypeMismatchException, org.springframework.beans.factory.config.BeanExpressionContext, .BeanExpressionResolver, .ConfigurableBeanFactory, org.springframework.core.KotlinDetector, .MethodParameter, .ReactiveAdapterRegistry, org.springframework.lang.Nullable, org.springframework.ui.Model, org.springframework.web.bind.WebDataBinder, org.springframework.web.bind.annotation.ValueConstants, org.springframework.web.reactive.BindingContext, org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport, org.springframework.web.server.MissingRequestValueException, .ServerErrorException, .ServerWebExchange, .ServerWebInputException

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.

Authors
Rossen Stoyanchev, Sebastien Deleuze
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AbstractNamedValueArgumentResolver.KotlinDelegate

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

protected static class
AbstractNamedValueArgumentResolver.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, AbstractNamedValueArgumentResolver.NamedValueInfo>
Inherited from org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport:
logger

Constructor Summary

AccessConstructor and Description
public
AbstractNamedValueArgumentResolver(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
factory
,
ReactiveAdapterRegistry
for checking reactive type wrappers
registry
)

Create a new AbstractNamedValueArgumentResolver instance.

Method Summary

Modifier and TypeMethod and Description
private Object
applyConversion(Object value, AbstractNamedValueArgumentResolver.NamedValueInfo namedValueInfo, MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange)

Apply type conversion if necessary.

protected abstract AbstractNamedValueArgumentResolver.NamedValueInfo

Returns:

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

Create the NamedValueInfo object for the given method parameter.

private Mono<Object>
getDefaultValue(AbstractNamedValueArgumentResolver.NamedValueInfo namedValueInfo, MethodParameter parameter, BindingContext bindingContext, Model model, ServerWebExchange exchange)

Resolve the default value, if any.

private AbstractNamedValueArgumentResolver.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
,
ServerWebExchange
the current exchange
exchange
)

Invoked when a named value is required, but resolveName(String, MethodParameter, ServerWebExchange) 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, ServerWebExchange) returned null and there is no default value.

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
,
Model
the model
model
,
ServerWebExchange
the current exchange
exchange
)

Invoked after a value is resolved.

public Mono<Object>
resolveArgument(MethodParameter
the method parameter
parameter
,
BindingContext
the binding context to use
bindingContext
,
ServerWebExchange
the current exchange
exchange
)

Implements org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver.resolveArgument.

Resolve the value for the method parameter.

private Object
resolveEmbeddedValuesAndExpressions(String value)

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

protected abstract Mono<Object>

Returns:

the resolved argument (may be empty Mono)
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
,
ServerWebExchange
the current exchange
exchange
)

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

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

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

Inherited from org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport:
checkAnnotatedParamNoReactiveWrappercheckParameterTypecheckParameterTypeNoReactiveWrappergetAdapterRegistry

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, AbstractNamedValueArgumentResolver.NamedValueInfo> namedValueInfoCache

Constructor Detail

AbstractNamedValueArgumentResolverback to summary
public AbstractNamedValueArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry)

Create a new AbstractNamedValueArgumentResolver instance.

Parameters
factory: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

registry:ReactiveAdapterRegistry

for checking reactive type wrappers

Method Detail

applyConversionback to summary
private Object applyConversion(Object value, AbstractNamedValueArgumentResolver.NamedValueInfo namedValueInfo, MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange)

Apply type conversion if necessary.

Annotations
@Nullable
createNamedValueInfoback to summary
protected abstract AbstractNamedValueArgumentResolver.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:AbstractNamedValueArgumentResolver.NamedValueInfo

the named value information

getDefaultValueback to summary
private Mono<Object> getDefaultValue(AbstractNamedValueArgumentResolver.NamedValueInfo namedValueInfo, MethodParameter parameter, BindingContext bindingContext, Model model, ServerWebExchange exchange)

Resolve the default value, if any.

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

Obtain the named value for the given method parameter.

handleMissingValueback to summary
protected void handleMissingValue(String name, MethodParameter parameter, ServerWebExchange exchange)

Invoked when a named value is required, but resolveName(String, MethodParameter, ServerWebExchange) 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

exchange:ServerWebExchange

the current exchange

Annotations
@SuppressWarnings:UnusedParameters
handleMissingValueback to summary
protected void handleMissingValue(String name, MethodParameter parameter)

Invoked when a named value is required, but resolveName(String, MethodParameter, ServerWebExchange) 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

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, Model model, ServerWebExchange exchange)

Invoked after a value is resolved.

Parameters
arg:Object

the resolved argument value

name:String

the argument name

parameter:MethodParameter

the argument parameter type

model:Model

the model

exchange:ServerWebExchange

the current exchange

Annotations
@SuppressWarnings:UnusedParameters
resolveArgumentback to summary
public Mono<Object> resolveArgument(MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange)

Implements org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver.resolveArgument.

Doc from org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver.resolveArgument.

Resolve the value for the method parameter.

Parameters
parameter:MethodParameter

the method parameter

bindingContext:BindingContext

the binding context to use

exchange:ServerWebExchange

the current exchange

Returns:Mono<Object>

Mono for the argument value, possibly empty

Annotations
@Override
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 Mono<Object> resolveName(String name, MethodParameter parameter, ServerWebExchange exchange)

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)

exchange:ServerWebExchange

the current exchange

Returns:Mono<Object>

the resolved argument (may be empty Mono)

updateNamedValueInfoback to summary
private AbstractNamedValueArgumentResolver.NamedValueInfo updateNamedValueInfo(MethodParameter parameter, AbstractNamedValueArgumentResolver.NamedValueInfo info)

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

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

private Class AbstractNamedValueArgumentResolver.KotlinDelegate

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.result.method.annotation.AbstractNamedValueArgumentResolver.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.reactive.result.method.annotation back to summary

protected Class AbstractNamedValueArgumentResolver.NamedValueInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.result.method.annotation.AbstractNamedValueArgumentResolver.NamedValueInfo
Known Direct Subclasses
org.springframework.web.reactive.result.method.annotation.CookieValueMethodArgumentResolver.CookieValueNamedValueInfo, org.springframework.web.reactive.result.method.annotation.ExpressionValueMethodArgumentResolver.ExpressionValueNamedValueInfo, org.springframework.web.reactive.result.method.annotation.MatrixVariableMethodArgumentResolver.MatrixVariableNamedValueInfo, org.springframework.web.reactive.result.method.annotation.PathVariableMethodArgumentResolver.PathVariableNamedValueInfo, org.springframework.web.reactive.result.method.annotation.RequestHeaderMethodArgumentResolver.RequestHeaderNamedValueInfo, org.springframework.web.reactive.result.method.annotation.RequestParamMethodArgumentResolver.RequestParamNamedValueInfo

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)