Serde supports applying custom attributes that are used with #[derive(Serialize)]
:
#[derive(Serialize)]
struct Resource {
// Always serializ
You implement attributes on fields as part of the derive macro for the struct (you can only implement derive macros for structs and enums).
Serde does this by checking every field for an attribute within the structures provided by syn
and changing the code generation accordingly.
You can find the relevant code here: https://github.com/serde-rs/serde/blob/master/serde_derive/src/internals/attr.rs