Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-value query parameters #6118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

kwondh5217
Copy link
Contributor

Motivation:

This PR is a follow-up to #6072, which added support for mapping all query parameters into a Map<String, String>. However, it does not handle cases where multiple values exist for the same query parameter key.

For example:

GET /foo?a=1&a=2&b=3

The current implementation only retains the last value a=2, losing a=1.
To better support multi-value query parameters, we introduce support for Map<String, List<?>>.

Modifications:

  • Enhanced ofQueryParamMap in AnnotatedValueResolver to support:
    • Map<String, String> → Single-value mapping (existing behavior).
    • Map<String, List> → Multi-value mapping (new behavior).
  • If the value type of the map is List<?>, query parameters with the same key are collected into a list.
  • Added validation to ensure that the value type is List<?>. If an unsupported type is used, an IllegalArgumentException is thrown.

Result:

  • Users can now use @param Map<String, List<?>> to collect multi-value query parameters.

@ikhoon ikhoon added this to the 1.33.0 milestone Feb 24, 2025
@kwondh5217 kwondh5217 requested a review from ikhoon February 24, 2025 12:19
@kwondh5217 kwondh5217 changed the title Support multi-value query parameters with @Param Map<String, List<?>> Support multi-value query parameters Feb 24, 2025
Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left small suggestions. Thanks!

@kwondh5217
Copy link
Contributor Author

Thanks for the suggestions, @minwoox!
I’ve pushed the updates now.

@kwondh5217 kwondh5217 force-pushed the main branch 2 times, most recently from efa40e2 to 236cb7f Compare April 9, 2025 11:39
Signed-off-by: Daeho Kwon <trewq231@naver.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants