Closed birhburh closed 3 weeks ago
Thanks for PR!
I do not have a very strong opinion, but I feel like I would rather have this behavior being optional, maybe some special attribute about serializing as "null"?
oh, why do I always vargue in nanoserde's PRs :facepalm:
you are right, null
is the way!
I just opened JSON standard and it says pretty clear that null
is supposed to be serialized as null
and nothing about removing fields.
I still feel like it would be nice to have an option to skip None's in serialized json, even if they got a default value, but maybe there should be an attribute for skipping, not for adding?
Checked how they skip on None in serde and of course i forgot about
#[serde(skip_serializing_if = "Option::is_none")]
Adding this to my nanoserde todo list
#[serde(skip_serializing_if = "Option::is_none")]
looks good, but I think it would make more sense to have it another way around: skip serializing by default, and write null
if the attribute is set. This way we will avoid a breaking change while support all the use cases where this null is important
Added serialize_none_as_null for struct and fields, and changed test accordingly
Thanks @birhburh, sorry was slow to review
During porting of parsing lottie files to this project from lottie-rs I comparing serialized data and nanoserde was skipping None fields with default attribute during serialization, but serde serializes them as null