-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Constructor binding fails for simple types List/Map/Array and for nested container combinations #34305
Comments
I found a similar issue with a set nested in a map: @RestController
class HelloController {
@GetMapping("/test")
fun index(filterExample: FilterExample): String {
return filterExample.toString()
}
}
data class FilterExample(@RequestParam(required = false) var testMap: Map<String,Set<String>>? = null) error is an example project is here: https://github.com/apirkl/demoDataBinding |
Use IllegalArgumentException instead of NumberFormatException. spring-projectsgh-34305. Signed-off-by: Mengqi Xu <2663479778@qq.com>
I add a test case: @Test // gh-34205
void createBinderViaConstructorWithChooseConstructor() {
request.addParameter("Some-Int-Array[0]", "1");
ServletRequestDataBinder binder = new ExtendedServletRequestDataBinder(null);
binder.setTargetType(ResolvableType.forClass(DataBean.class));
binder.setNameResolver(new BindParamNameResolver());
assertThatThrownBy(() -> binder.construct(request))
.isInstanceOf(IllegalStateException.class)
.hasMessage("No primary or single unique constructor found for class java.lang.Integer");
}
private record DataBean(String name, int age, @BindParam("Some-Int-Array") Integer[] someIntArray) {
} For |
@VladM-N1 and @apirkl, are you claiming that these use cases were supported in previous versions of Spring Framework? If so, with which version(s) of the Spring Framework did those use cases work? @apirkl, have you tested with Spring Framework 6.2.2? |
Hi @sbrannen Also one of the cases with databinding covered here, but only for ServletDataBinding edit:
|
@sbrannen Thanks for taking a look! Yep if you check the example project it's forcing the spring version in gradle.properties and I confirmed it is using 6.2.2. Also yeah I'd expect it to be supported, the issue comes from the way #32426 was implemented. It was working correctly using The issue is the spring-framework/spring-context/src/main/java/org/springframework/validation/DataBinder.java Line 1063 in 673e2b0
|
In 6.1 In 6.2 What I don't see is how this could have worked in 6.1.x where we simply didn't have such support. @VladM-N1, I tried your sample with 3.3.0 but it doesn't work, which is expected because the parameter names alone (e.g.
I am marking it as a bug for now, but will change to regression if it was indeed possible before. |
Hi @rstoyanchev
|
The Kotlin branch uses a data class which is constructed with empty input initially (since we did not support constructor binding with map/list/array). However, the setter binding applied after that succeeds, and the tests pass. The Java branch uses a record and it can only be initialized through the constructor. As expected, I get failures in the Java branch with both Boot 3.3.0 and 2.7.18. So this is a regression when using Kotlin data classes, but not for Java records. |
Hi @rstoyanchev thanks for verifying this issue. |
Hi @rstoyanchev
|
@VladM-N1, we now have support for List/Map/Array of simple types, as the issue states, in addition to complex objects with nested paths. However, I shouldn't have closed the issue just yet. I meant to look into the |
Hi @rstoyanchev |
Hello,
It's first time I'm reporting bug here.
I've found bunch of bugs in recent spring version (6.2.2) related to query parameters. I can see that few of them were already fixed (#34121)
Here is 3 more that I've found:
Thanks for contributing to project and best regards
Code to reproduce:
GH project: https://github.com/VladM-N1/spring-622-bugs/blob/main/src/test/java/org/example/queryparamsbugs/BrokenQueryParamsTest.java
As code:
The text was updated successfully, but these errors were encountered: