Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task] Add Option to Create Collections without Optional Wrapping #631

Open
MelleD opened this issue Jul 30, 2024 · 0 comments
Open

[Task] Add Option to Create Collections without Optional Wrapping #631

MelleD opened this issue Jul 30, 2024 · 0 comments
Labels
acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps. task

Comments

@MelleD
Copy link
Contributor

MelleD commented Jul 30, 2024

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/

@MelleD MelleD added the task label Jul 30, 2024
@chris-volk chris-volk added the acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps. label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged Has been viewed by one of the maintainers and is ready for further work, discussion or other steps. task
Projects
None yet
Development

No branches or pull requests

2 participants