Attribute Macro serde_with::serde_as[][src]

#[serde_as]

Convenience macro to use the serde_as system.

The serde_as system is designed as a more flexible alterative to serde’s with-annotation.

Example

use serde_with::{serde_as, DisplayFromStr};
use std::collections::HashMap;

#[serde_as]
#[derive(Serialize, Deserialize)]
struct Data {
    /// Serialize into number
    #[serde_as(as = "_")]
    a: u32,

    /// Serialize into String
    #[serde_as(as = "DisplayFromStr")]
    b: u32,

    /// Serialize into a map from String to String
    #[serde_as(as = "HashMap<DisplayFromStr, _>")]
    c: Vec<(u32, String)>,
}

Alternative path to serde_with crate

If serde_with is not available at the default path, its path should be specified with the crate argument. See re-exporting serde_as for more use case information.

#[serde_as(crate = "::some_other_lib::serde_with")]
#[derive(Deserialize)]
struct Data {
    #[serde_as(as = "_")]
    a: u32,
}