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

Support for java.util.Optional as a @RequestParam [SPR-11829] #16448

Closed
spring-projects-issues opened this issue May 29, 2014 · 1 comment
Closed

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented May 29, 2014

Graham Cox opened SPR-11829 and commented

Java 8 adds the new java.util.Optional type to represent values that might or might not have a value. I've just tried using this as a controller parameter that is annotated with @RequestParam and it unfortunately doesn't work.

If the request parameter is missing then the method parameter comes through as null, and if it is present then Spring throws an java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Optional]: no matching editors or conversion strategy found.

It would be very useful if these came through as either Optional.EMPTY or Optional.of(param). I am currently doing this right at the top of my controller methods - essentially I'm wrapping the values in Optional.ofNullable() - but if Spring did this automatically that would be fantastic.


Affects: 4.0.5

Issue Links:

  • INT-3516 Support JDK8 Optional<?> When Binding Messages to Service Methods
  • #16452 Support for java.util.Optional with @Inject (a la @Autowired's required=false)
  • #17245 Support for java.util.Optional as a @RequestPart
  • #17997 Request parameters cannot bind to Optional<List>
  • #19574 Support for java.util.Optional as a @RequestBody

Referenced from: commits 0dc6082

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
2 participants