-
Notifications
You must be signed in to change notification settings - Fork 38.5k
WebDataBinder different behaviour between 6.0.x and 6.1.x - spring boot 3.0x and 3.2.x #33279
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
Comments
Thanks for the sample project. In 6.0.x, the argument resolver for From what I can see, your goal is to support request params with characters that do not map to Java variable names. This is now supported with constructor binding and the public class SearchCriteria {
private final String name;
@BindParam("$page")
private final int page;
@BindParam("$size")
private final int size;
public SearchCriteria(String name, int page, int size) {
this.name = name;
this.page = page;
this.size = size;
}
public String getName() {
return name;
}
public int getPage() {
return page;
}
public int getSize() {
return size;
}
} The same also works as a record: public record SearchCriteria (
String name, @BindParam("$page") int page, @BindParam("$size") int size) {
} In summary, the difference you have pointed out is expected, and |
Thanks a lot for the context and the workaround. Just tried to use the constructor args on my project and it works perfectly. No need to use the custom binder anymore. Since there is no real bug I'm closing this issue. |
Uh oh!
There was an error while loading. Please reload this page.
Hello
Description:
I'm investigating a possible bug with the Spring webDataBinder. Based on my understanding, this issue is reproducible on Spring Boot 3.2.x and 3.1.x, but not on Spring Boot 3.0.x. More specifically, the problem appears in Spring Web 6.1.x.
Sample Project: https://github.com/hugo-ma-alves/webbinder-bug
Related Issues:
This issue might be related to a previous one: #32919.
Expected behaviour
When invoking the following endpoint: http://localhost:8080/?%24page=50&%24size=1&name=example, it is expected that the SearchCriteria argument of the controller is populated with all the parameters sent in the URL, including $page and $size.
The controller should echo what it receives. The expected output is: example|50|1.
To map the $page and $size parameters, I created a binder (PaginationParametersBinder) that binds these parameters to the correct POJO property.
Difference of behaviour between web 6.0.x and 6.1.x
On spring web 6.0.x the binder.getTarget(); returns a instance of my target pojo.
With this instance I can then invoke the binder.bind(propertyValues); and the values are correctly binded.
However, on web 6.1.x the binder.getTarget() returns null.
I refactored the code a bit to not rely on the target but just on the target class:
But this change will later cause the following error when invoking the .bind()
Steps to Reproduce using a unit test
This time, the test will fail because the $page and $size parameters are not bound to the POJO.
Can you please help to understand if this is a bug or a change of behaviour introduced by spring web 6.1.x?
Thank you
The text was updated successfully, but these errors were encountered: