1

I have read here https://stackoverflow.com/a/9768635/258483 that Spring MVC will populate an array with multiple values of single name parameter.

But how would I know this without experiment or without asking SO?

The Javadoc about @RequestParam is very poor and contain no word about arrays.

What is the full and reliable information source on the topic?

Community
  • 1
  • 1
Dims
  • 47,675
  • 117
  • 331
  • 600

1 Answers1

0

RequestParamMethodArgumentResolver Resolves method arguments annotated with @RequestParam, which extends AbstractNamedValueMethodArgumentResolver. AbstractNamedValueMethodArgumentResolver creates a WebDataBinder to apply type conversion to the resolved argument value if it doesn't match the method parameter type. Lets take a look at some part of resolveArguemnt method:

            try {
                arg = binder.convertIfNecessary(arg, paramType, parameter);
            }
            catch (ConversionNotSupportedException ex) {
                throw new MethodArgumentConversionNotSupportedException(arg, ex.getRequiredType(),
                        namedValueInfo.name, parameter, ex.getCause());
            }
            catch (TypeMismatchException ex) {
                throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(),
                        namedValueInfo.name, parameter, ex.getCause());

For RequestParam, binder.convertIfNecessary uses up to 116 different Converters to possibly convert from passed String to required param, e.g. List. Some of possible conversions are:

  • String => Enum
  • String => Properties
  • String => Collection

I guess the only way to debug resolveArgument method.

Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151