Last active
November 8, 2021 16:41
-
-
Save cr0wst/8bdd1704e3eba5ae5a77b6e661de131d to your computer and use it in GitHub Desktop.
JpaSpecificationRepository Nullable Extension Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* By default [JpaSpecificationExecutor.findOne] returns an Optional. This extension function wraps it to return a nullable instead. | |
*/ | |
fun <T> JpaSpecificationExecutor<T>.findOneOrNull(specification: Specification<T>): T? = | |
findOne(specification) | |
.orElse(null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment