use serde::{Deserialize, Deserializer};
pub fn null_as_default<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
T: Deserialize<'de> + Default,
D: Deserializer<'de>,
{
Option::<T>::deserialize(deserializer).map(Option::unwrap_or_default)
}
pub fn reject_if_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
where
T: Deserialize<'de>,
D: Deserializer<'de>,
{
let value = Option::<T>::deserialize(deserializer)?;
if value.is_some() {
return Err(serde::de::Error::custom("unexpected value"));
}
Ok(value)
}