Affects: Spring 5.3. 16 and below

Currently in Spring, there is only one class Optional<T> that can be populated by a null value when annotated with @RequestParam in a given RestControllerMapping.

This is allowed because within Spring a private method checks to see if the class of the type Optional and will immediately return an Optional.empty() when a null value is received.

In my case, I would like to use the class Option from the arrow library so I can differentiate between an incoming request to query for null vs a request never being sent.

this allows me to do something like this

@RequestMapping age: Option

Where

Option.none() is equivalent to not querying by age Option.some(null) is equivalent to querying for entries where age is null Option.some(123) is equivalent to querying for entries where age is 123

This allows me to dynamically build SQL predicates

In all cases except for Optional however, Spring will throw an exception if the parameter is not passed.

Comment From: rstoyanchev

You should be able to register a custom converter for this. That should be checked before the Optional check in TypeConverterDelegate.

Comment From: codymikol

I'll give this a try and report back, thanks!

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.