Affects: 4.1+
Spring supports java8 generic Optional<?>
as a request parameter (see #16448 0dc6082).
But there are value-based primitive counterparts:
* java.util.OptionalInt
* java.util.OptionalLong
* java.util.OptionalDouble
which are not supported. For example, simple controller methods like this
@GetMapping
void doSomething(@RequestParam OptionalLong filterId)
require cumbersome fiddling with converters and method argument resolvers.
Is it worth implementing these types as well to get more consistent behavior? Such classes are quite useful especially in conjunction with primitive streams or custom primitive collections (we use fastutils). Their apis usually offer bare primitive types instead of boxed wrappers. Sure, it is possible to get it working without extra config just with generic Optional<BoxedType>
and some manual casts here and there, it just feels unnecessary.
Comment From: sbrannen
Hi @cart-before-horse,
Congratulations on submitting your first issue for the Spring Framework! 👍
Is it worth implementing these types as well to get more consistent behavior?
Due to the added complexity required to support all Optional
variants consistently across the code base, we do not feel it is worth supporting those types.
In light of that, I am closing this issue.
Regards,
Sam