This is a simple example, but the value of this feature is realized when you have a query that contains many optional parameters. Creating all possible permutations can get very complicated. I believe having Optional would greatly simplify many use cases.
Note that while Optional can currently be used in a repository method parameter, it does not behave as expected. The current behavior is to query for a null value when passed Optional.empty(). I believe this is counter-intuitive since Spring Data MongoDB does not normally insert null fields in the database. If a field has a null value, that field does not exist in the mongo document
DATACMNS-768 Support Optional on repository query parameters
DATACMNS-490 Add support for optional query method parameters
The text was updated successfully, but these errors were encountered:
We already support Optional as argument in the sense of being a wrapper for null. This type of conversion is handled at Spring Data Commons level for a consistent functionality across all Spring Data modules so we cannot change this kind of behavior without breaking existing code