Motivation:
Make it possible to format Collection
, @RequestParam
arguments to a single String value. On the server side, the ConversionService
parses a String value to the target method parameter type. On the client side, the reverse could be done to format the MethodParameter
to a String.
See original request and discussion under #33154.
Modifications:
Add customization for handling collection types to RequestParamArgumentResolver
Additional info:
- I plan to polish the code after checking with the maintainer to make sure I'm working in the direction I intended.
- If we have a way to format it according to the checkstyle rules, please let me know 🙏
Comment From: doljae
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 @Collectionformat
supports.
Comment From: yvasyliev
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 @CollectionFormat
alternative for HTTP Interface to be applied to each request parameter individually. It will provide users with high customization capabilities:
@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`
}
Comment From: doljae
Hello @yvasyliev . I'm not the one who you mentioned but I received an email from your comment. You can use it with milestone version and please check my issue comment.
As I know, you're right. Currently we can decide only one way of handling collection values with @RequestParam
annotation in single declarative HTTP interface.
I'm not the maintainer but I think Spring core already have an ArgumentResolver
and it's derived class, we can decide the way to handle collection values with registering customized ArgumentResolver
class. @CollectionFormat
's implementation is different from the one in spring core and I'm guessing that their intent is to be cautious about adding new annotations. Again, this is just my opinion 🙂