-
Notifications
You must be signed in to change notification settings - Fork 926
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 for HTTP GET map parameters #6072
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Daeho Kwon <[email protected]>
Signed-off-by: Daeho Kwon <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI, @kwondh5217, thanks for the PR. 😉
Would you add an e2e test that verifies if this change works?
GET http://127.0.0.1:xxx/map?a=b&c=d
@Get("/map")
public HttpResponse map(@Params Map<String, Object> map) {...}
Signed-off-by: Daeho Kwon <[email protected]>
@minwoox Thanks for your comment! |
Signed-off-by: Daeho Kwon <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically looks good. Left just nits. 👍
core/src/test/java/com/linecorp/armeria/internal/server/annotation/AnnotatedServiceTest.java
Outdated
Show resolved
Hide resolved
@@ -358,19 +359,30 @@ private static void testResolver(AnnotatedValueResolver resolver) { | |||
} else { | |||
if (String.class.isAssignableFrom(resolver.elementType())) { | |||
assertThat(value).isEqualTo(""); | |||
} else if (QUERY_PARAM_MAP.equals(resolver.httpElementName())) { | |||
assertThat(value).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this line of code is not invoked. Would you explain why you've added this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minwoox Thank you for pointing this out! 🙇
This line was added by mistake and isn't necessary. I've removed it now. Appreciate your attention to detail!
@@ -458,6 +460,11 @@ private static AnnotatedValueResolver of(AnnotatedElement annotatedElement, | |||
final Param param = annotatedElement.getAnnotation(Param.class); | |||
if (param != null) { | |||
final String name = findName(typeElement, param.value()); | |||
// If the parameter is of type Map and the @Param annotation does not specify a value, | |||
// map all query parameters into the Map. | |||
if (Map.class.isAssignableFrom(type) && DefaultValues.isUnspecified(param.value())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about raising an exception if the value is specified?
if (Map.class.isAssignableFrom(type)) {
if (DefaultValues.isSpecified(param.value())) {
// throw an exception...
}
return ofQueryParamMap(name, annotatedElement, typeElement, type, description);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minwoox Thank you for the suggestion! 🙇
I've updated the code to raise an exception when a value is specified for a Map parameter and added the test cases. Please take a look when you have time.
Signed-off-by: Daeho Kwon <[email protected]>
Signed-off-by: Daeho Kwon <[email protected]>
Motivation:
This pull request addresses #6058
Currently,
@Param
cannot be mapped to a Map, but this change enables that functionality, allowing query parameters to be handled as a Map.Modifications:
AnnotatedValueResolver
to detect when a parameter is of type Map and the@Param
annotation has an unspecified value.@Param
value is explicitly specified.ofQueryParamMap
to handle the creation of an AnnotatedValueResolver for mapping all query parameters into a Map.@Param
value is unspecified and the parameter type is Map.Result:
@Param
asMap<String, Object>
to handle all query parameters.