This repository was archived by the owner on Jun 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Introduce a skip_if_null attribute #118
Copy link
Copy link
Open
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.