[Task] Add Option to Create Collections without Optional Wrapping #631
Labels
acknowledged
Has been viewed by one of the maintainers and is ready for further work, discussion or other steps.
task
In Java, it is considered a best practice or common sense to avoid using Optional for Collections. Instead, Collections should be returned directly, either as null instances or as empty collections if there is no data.
Currently, ESMF generates Collections wrapped in Optional, which goes against this best practice. I propose adding an option in ESMF to allow Collections to be created without using Optional (backward compatible).
Proposed Changes:
Add Configuration Option: Introduce a configuration option that specifies whether Collections should be wrapped in Optional. The default behavior should remain the same for backward compatibility.
Option Name: wrapCollectionsInOptional
Possible Values: true (default), false
When wrapCollectionsInOptional is set to false, Collections should be created without Optional wrapping.
Default Value Handling: Introduce an additional configuration option to define the default value of Collections when there is no data. Users should have the choice to return either null or an empty Collection.
Option Name: defaultCollectionValue
Possible Values: null, empty (default)
When defaultCollectionValue is set to empty, empty Collections should be returned if there is no data. If set to null, null should be returned.
Links
https://blog.indrek.io/articles/misusing-java-optional/
https://mohammed-atif.medium.com/are-you-correctly-using-collections-optionals-and-nulls-in-your-java-code-7316dd30f53a
https://dev.to/ivangavlik/how-to-use-the-optional-class-java-3pf5
https://blog.jooq.org/divided-we-stand-optional/
The text was updated successfully, but these errors were encountered: