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

Implement @embedNullable for serialization #2405

merged 1 commit into from Feb 19, 2020


Copy link

Fixes #1541 and is an alternative, simpler implementation of #1650

this adds an embedNullable UDA which specially treats std.typecons.Nullable without values as not defined. This makes it ignored during serialization.

This transparently makes the type hidden for a serializer if it's not given and thus allows special states like:

  • undefined == Nullable!T.init (not in output at all)
  • null == Nullable!T(null) (in output like usual for T == null)
  • value == Nullable!T(value) (in output like usual)

Use case:

  • patch structs where only the fields which should be applied are set to non-nullified values, so they allow patching to null and any other value

Doesn't repurpose @optional to keep backwards compatibility and avoid ambiguous definitions of "what's the ignored value" for an optional value.

Copy link

I'll still have to look at the code in detail, but the approach looks good to me! Can you do a rebase to (hopefully) make the CI pass?

Fixes vibe-d#1541 and is an alternative, simpler implementation of vibe-d#1650
Copy link
Contributor Author

ok done

Copy link

It might make sense to put some additional thought into alternative names for the attribute in the future, but there was no name that immediately crossed my mind, so in any case, let's go with this.

@s-ludwig s-ludwig merged commit 3c7cb0a into vibe-d:master Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

Use of @optional attribute while serializing
2 participants