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.
Problem
A common scenario when serializing structs is to skip fields that are
null
. Currently, you have to write your ownserialize
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 notnull
. For deserialization, if the final value we would have assigned to the final field/variant value isnull
, then we can just skip assigning the field.Alternatives
No response
Additional Context
No response