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

RequestParam can't properly parse an optional boolean parameter [SPR-5410] #10083

Closed
spring-projects-issues opened this issue Jan 14, 2009 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Scott Battaglia opened SPR-5410 and commented

I'm using the Spring MVC's annotation-based support and specified a method signature as follows:

public void validateCas10Request(@RequestParam(value="renew",required=false) final boolean renew, @RequestParam(value="service",required=true) final String service, @RequestParam(value="ticket",required=true) final String ticket, final Writer writer) {

If I do not have a renew request parameter the following error is thrown:
java.lang.IllegalStateException: Optional boolean parameter 'renew' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.

Is there a reason that a null parameter is not converted to false, as per the JavaDoc's parseBoolean method for Boolean?
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Boolean.html#parseBoolean(java.lang.String)


Affects: 2.5.6

@spring-projects-issues
Copy link
Collaborator Author

Scott Battaglia commented

This can be alleviated with:
http://jira.springframework.org/browse/SPR-5237

But again, the javadoc for Boolean says that if you call parseBoolean, a null is essentially false.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point - it makes sense to fall back to "false" for such an optional boolean parameter. Supported as of 3.0 M2.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants