diff --git a/src/entities/account.rs b/src/entities/account.rs index 8cb22b2..eadd2a5 100644 --- a/src/entities/account.rs +++ b/src/entities/account.rs @@ -4,6 +4,7 @@ use chrono::prelude::*; use reqwest::multipart::Form; use ::Result; use std::path::Path; +use serde::de::{self, Deserialize, Deserializer, Unexpected}; /// A struct representing an Account. #[derive(Debug, Clone, Deserialize)] @@ -51,10 +52,35 @@ pub struct Account { #[derive(Debug, Clone, Deserialize)] pub struct Source { privacy: ::status_builder::Visibility, + #[serde(deserialize_with = "string_or_bool")] sensitive: bool, note: String, } +fn string_or_bool<'de, D: Deserializer<'de>>(val: D) + -> ::std::result::Result +{ + #[derive(Clone, Debug, Deserialize)] + #[serde(untagged)] + pub enum BoolOrString { + Bool(bool), + Str(String), + } + + Ok(match BoolOrString::deserialize(val)? { + BoolOrString::Bool(b) => b, + BoolOrString::Str(ref s) => { + if s == "true" { + true + } else if s == "false" { + false + } else { + return Err(de::Error::invalid_value(Unexpected::Str(s), &"true or false")); + } + } + }) +} + pub struct CredientialsBuilder<'a> { display_name: Option<&'a str>, note: Option<&'a str>,