Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Introduce a skip_if_null attribute #118

@phan-do

Description

@phan-do

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

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions