You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Thank you so much for the work you've put in the serde integration. We used to have a custom crate to overwrite some of the behavior of older versions of this package (to respect some of the serde macros), but I gave a go at using what's now on main and it works great!!!
I only have one comment. it's not uncommon to have large structs, and for these to have a bunch of optional fields. When that happens, one might want to not serialize the None fields (say you are writing documents to a database, outputting data as JSON for an API, ...). There, folks often use the serde_as crate, as such:
here with just one optional fields it's just overkill, but when you have a lot of them it's very elegant to use that "struct-wide" #[skip_serializing_none] rather than having to set a skip serialize attribute on all optional fields. Unfortunately, that doesn't seem to work at the moment (previous version of the code actually didn't complain about these things, likely because it ignored serde stuff altogether?). Instead, it shows me this error:
#[serde(skip_serializing)]` and `#[serde(skip_serializing_if)]` require `#[avro(default = "..")]
That is solved by, as stated, adding a #[avro(default = "null") on all the optional fields of the struct.
But, it would be a bit more elegant if it could just automatically infer that the default should be null/None for these optional fields, so we could still use serde_as + skip_serializing_none
Extend AvroSchemaComponent with a default function
/// Set the default value for this type if it is used in a record.////// Provided implementation returns `None` indicating that this type does not have a default value.fndefault() -> Option<serde_json::Value>{None}
In the derive implementation we would first look if the user set a override via the field attribute default and then fall back to the trait. This would mean that all Options would have a default in the next release.
Activity
Kriskras99 commentedon Jan 25, 2026
Maybe we could do the following:
AvroSchemaComponentwith adefaultfunctionOption<T>defaultdefaultand then fall back to the trait. This would mean that allOptions would have a default in the next release.@martin-g what do you think?