diff --git a/secrecy/Cargo.toml b/secrecy/Cargo.toml index 6220ebdd..edb0f87b 100644 --- a/secrecy/Cargo.toml +++ b/secrecy/Cargo.toml @@ -21,7 +21,7 @@ rust-version = "1.60" zeroize = { version = "1.6", default-features = false, features = ["alloc"] } # optional dependencies -serde = { version = "1", optional = true, default-features = false } +serde = { version = "1", optional = true, default-features = false, features = ["alloc"] } [package.metadata.docs.rs] all-features = true diff --git a/secrecy/src/lib.rs b/secrecy/src/lib.rs index 184e45c7..5c714b08 100644 --- a/secrecy/src/lib.rs +++ b/secrecy/src/lib.rs @@ -251,6 +251,16 @@ where } } +#[cfg(feature = "serde")] +impl<'de> Deserialize<'de> for SecretString { + fn deserialize(deserializer: D) -> Result + where + D: de::Deserializer<'de>, + { + String::deserialize(deserializer).map(Into::into) + } +} + #[cfg(feature = "serde")] impl Serialize for SecretBox where