-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Allow formatting of Collection values for @RequestParam
with HTTP interface client
#33220
Conversation
@RequestParam
with HTTP interface client
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.
Looking at the changes so far, I've decided to make the following update dcabddd to make it easier access to HttpExchange
metadata in argument resolvers. Now RequestParamArgumentResolver
can override the overloaded createNamedValueInfo
method and get easy access to the HTTP method and content type.
See further comments below.
...-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java
Outdated
Show resolved
Hide resolved
...src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java
Outdated
Show resolved
Hide resolved
...src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java
Show resolved
Hide resolved
...src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java
Outdated
Show resolved
Hide resolved
On 95a76ee commit I tried to applying coding style which is used in the project. Please let me know if I need to make any additional changes. One more thing, I was wondering what your thoughts are on supporting a variety of delimiters besides the comma that |
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.
Thanks for the updates, I'll take it from here. For a different delimiter, you can customize the ConversionService
.
Hello @rstoyanchev, I need some clarification here. I've got a case where I need to support different collection encoding methods within the same HTTP Interface: @HttpExchange("/api/v1")
public interface MyClient {
@GetExchange("/list")
String sendList(List<String> params); // must be encoded as `params=value1¶ms=value2`
@GetExchange("/csv")
String sendCsv(List<String> params); // must be encoded as `params=value1,value2`
} Could you please suggest how can I achieve it after f967f6f? With Feign client I could do the following: @FeignClient("myClient")
public interface MyClient {
@GetMapping("/api/v1/list")
String sendList(List<String> params); // will be encoded as `params=value1¶ms=value2`
@CollectionFormat(feign.CollectionFormat.CSV)
@GetMapping("/api/v1/csv")
String sendCsv(List<String> params); // will be encoded as `params=value1,value2`
} I would expect to see a @HttpExchange("/api/v1")
public interface MyAnotherClient {
@GetExchange("/list")
String sendDifferentParams(
List<String> params,
@CollectionFormat(CSV) List<String> csvParams
); // will be encoded as `params=value1¶ms=value2&csvParams=value1,value2`
} |
Hello @yvasyliev . As I know, you're right. Currently we can decide only one way of handling collection values with I'm not the maintainer but I think Spring core already have an |
Motivation:
Make it possible to format
Collection
,@RequestParam
arguments to a single String value. On the server side, theConversionService
parses a String value to the target method parameter type. On the client side, the reverse could be done to format theMethodParameter
to a String.See original request and discussion under #33154.
Modifications:
Add customization for handling collection types to
RequestParamArgumentResolver
Additional info: