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

Introduce a skip_if_null attribute #118

Open
ibokuri opened this issue Jul 21, 2023 · 0 comments
Open

Introduce a skip_if_null attribute #118

ibokuri opened this issue Jul 21, 2023 · 0 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@ibokuri
Copy link
Contributor

ibokuri commented Jul 21, 2023

Problem

A common scenario when serializing structs is to skip fields that are null. Currently, you have to write your own serialize function and manually check nullable fields and then skip them, which is quite tedious to do when you have lots of these fields.

Proposal

A skip_if_null attribute can be added that'll be definable by all types that can specify a block. When applied to an optional field of a struct (or an optional variant of a union, etc.), the field/variant will be serialized only when it's value is not null. For deserialization, if the final value we would have assigned to the final field/variant value is null, then we can just skip assigning the field.

Alternatives

No response

Additional Context

No response

@ibokuri ibokuri added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jul 21, 2023
@ibokuri ibokuri added this to the 0.5.0 milestone Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

1 participant