Macro serde_with_tag

Source
macro_rules! serde_with_tag {
    (
        $(#[$attr:meta])*
        pub struct $name:ident<$lt:lifetime> {
            $(
                $(#[$doc:meta])*
                pub $field:ident: $ty:ty,
            )*
        }
    ) => { ... };
    (
        $(#[$attr:meta])*
        pub struct $name:ident {
            $(
                $(#[$doc:meta])*
                pub $field:ident: $ty:ty,
            )*
        }
    ) => { ... };
}
Expand description

A macro to tag a struct externally. With serde attributes, unfortunately it is not possible to serialize a struct to json with its name as key and its fields as value. Example: {"Example":{"Field1":"hello","Field2":"world"}}

Several models need to be serialized in that format. This macro uses a helper to serialize and deserialize to/from that format.

Resource: https://github.com/serde-rs/serde/issues/554#issuecomment-249211775