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

Allow nullable collections with useImmutableCollections=true #123

Open
fprochazka opened this issue Jul 19, 2022 · 1 comment
Open

Allow nullable collections with useImmutableCollections=true #123

fprochazka opened this issue Jul 19, 2022 · 1 comment
Labels
enhancement New feature or request PR welcome A PR submitted for this issue would be welcome

Comments

@fprochazka
Copy link

fprochazka commented Jul 19, 2022

Hi,
somewhat related to #122, I'd like to propose allowing collections to become nullable, because right now useImmutableCollections = true does two things

  • it adds the conversion to immutable collections (awesome!)
  • but also enforces that the output record can never have the collection values nullable

I'm proposing to change the behaviour based on interpretNotNulls value.

  • useImmutableCollections = true && interpretNotNulls = false
    • mapping will be return (o != null) ? Map.copyOf(o) : null;
  • useImmutableCollections = true && interpretNotNulls = true
    • and field is determined to be nullable
      • mapping will be return (o != null) ? Map.copyOf(o) : null;
    • and field is determined to be notnull
      • mapping will be return (o != null) ? Map.copyOf(o) : Map.of();
  • useImmutableCollections = true
    • current behaviour

This should also (consistently) affect the default value for collections mentioned in #122

@fprochazka fprochazka changed the title Allow nullable collections Allow nullable collections with useImmutableCollections=true Jul 19, 2022
@Randgalt Randgalt added PR welcome A PR submitted for this issue would be welcome enhancement New feature or request labels Sep 8, 2022
@hofiisek
Copy link
Contributor

hofiisek commented Oct 26, 2023

I started working on this and so far I got to a point where record components return null when a new useNullableCollections option is set to true (default is false for backwards compatibility). It does not yet take into account if nulls are interpreted or not.

I decided to create a new option for it to not break any existing code as I'd not be surprised if library users were relying on these collection/list/set/map components always being non-null. Please let me know if it should be done otherwise.

Randgalt pushed a commit that referenced this issue Nov 23, 2023
* Support nullable collections based on 'allowNullableCollections' and 'interpretNotNulls' options

* nit & typos

* Emit warning if allowNullableCollections is used in combination with non-specialized collections

---------

Co-authored-by: Dominik Hoftych <dominik.hoftych@shipmonk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR welcome A PR submitted for this issue would be welcome
Projects
None yet
Development

No branches or pull requests

3 participants