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
merged 1 commit into from
Feb 19, 2020

Conversation

WebFreak001
Copy link
Contributor

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.

@s-ludwig
Copy link
Member

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
@WebFreak001 WebFreak001 force-pushed the nullable-serialization branch from 9a05d47 to d793ac2 Compare February 19, 2020 12:17
@WebFreak001
Copy link
Contributor Author

ok done

@s-ludwig
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of @optional attribute while serializing
2 participants