-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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<Int?>
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.