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:
Referenced from: commits 0dc6082
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
@RequestParamand 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:
@Inject(a la@Autowired's required=false)@RequestPart@RequestBodyReferenced from: commits 0dc6082