Skip to content
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

Leniently bind "is" prefix for boolean properties (along the lines of Jackson) [SPR-16135] #20683

Open
spring-issuemaster opened this issue Oct 31, 2017 · 1 comment

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Oct 31, 2017

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

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 31, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.