I have an endpoint that accepts Set
@ResponseStatus(OK)
@GetMapping(value = "/people")
public PeopleResponse getPeople(@RequestParam(name = "idType2") Set<String> idsType1) {
return service.getPeople(idsType1);
}
and this works fine with both types of collection requestparam assignments resulting in 3 elements inside the set.
localhost:8080/foo/bar/people?idsType1=QWE,RTY,UIO
localhost:8080/foo/bar/people?idsType1=QWE&idsType1=RTY,&idsType1=UIO
However if I move the set into a wrapping class
@Value
@RequiredArgsConstructor
public class IdsType1 {
Set<String> idsType1;
}
@ResponseStatus(OK)
@GetMapping(value = "/people")
public PeopleResponse getPeople(
@Valid IdsType1 idsType1) {
(...)
The comma separated collection ends up being one element containing "QWE,RTY,UIO".
The reason why I wrap my set is because I actually have more parameters and I need to do a complex validation using custom validator. The code above is however the simplest code that unearths the problem that I'm having.
Spring 2.1.1-RELEASE Java 8 openjdk
Comment From: bclozel
I guess the Spring version is really the Spring Boot version; in both cases this version is out of support so please upgrade to a supported version.
In this case, I think you should reach out to StackOverflow to get help as this is really a question for your application and not a bug. You can look into type conversion in Spring MVC, as you probably need to teach Spring how to bind to your specific type.
Thanks!
Comment From: Wolowin
Ok sorry if this issue was misplaced.
In case anyone reaches this thread with similar issue the solution for me was to upgrade SpringBoot to 2.5.0+.