gtxx opened SPR-16135 and commented
I want to bind request parameters to User class instance, and there is a boolean field in User class.
1. controller class
@GetMapping("/test")
UserBo ttt(User user){
return user;
}
1. User.java
public class User {
private String username;
private Boolean isActive;
}
setter for isActive field works only if it's like this:
public void setIsActive(Boolean active) {
isActive = active;
}
If I use Intellij to generate setter and getter, setter is like this:
public void setActive(Boolean active) {
isActive = active;
}
with above setter, spring can't bind query parameter isActive to User.isActive.
Jackson can support both setters, I wonder if spring can improve query parameter binding like Jackson.
Affects: 4.3.10
Reference URL: https://stackoverflow.com/questions/16942193/spring-mvc-complex-object-as-get-requestparam
Comment From: spring-projects-issues
Juergen Hoeller commented
According to the JavaBeans convention, the name of the property "active" matches a setActive
method, and a property name "isActive" matches setIsActive
. The more common form is certainly the first, dropping the "is" prefix not only from the setter method but also from the property/parameter name.
That said, I wasn't aware that Jackson leniently binds the "is" prefix here. This makes it worth considering on our end as well.
Comment From: wagnerluis1982
I stumbled at this issue, I wonder if this is really relevant?