Fix deserialization of FlatDomainSettings boolean flags

This commit is contained in:
Brian Picciano 2023-07-18 19:05:51 +02:00
parent ccd2285b11
commit 63f4975d5a

View File

@ -1,9 +1,22 @@
use std::convert::TryFrom; use std::convert::TryFrom;
use serde::{Deserialize, Serialize}; use serde::{de, Deserialize, Serialize};
use crate::{domain, error::unexpected, origin}; use crate::{domain, error::unexpected, origin};
fn deserialize_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: de::Deserializer<'de>,
{
let s: &str = de::Deserialize::deserialize(deserializer)?;
match s {
"true" => Ok(true),
"false" => Ok(false),
_ => Err(de::Error::unknown_variant(s, &["true", "false"])),
}
}
#[derive(Serialize, Deserialize, Default)] #[derive(Serialize, Deserialize, Default)]
pub struct FlatDomainSettings { pub struct FlatDomainSettings {
domain_setting_origin_descr_kind: String, domain_setting_origin_descr_kind: String,
@ -14,8 +27,11 @@ pub struct FlatDomainSettings {
domain_setting_origin_descr_proxy_url: Option<String>, domain_setting_origin_descr_proxy_url: Option<String>,
#[serde(default)] #[serde(default)]
#[serde(deserialize_with = "deserialize_bool")]
domain_setting_serve_protocol_http: bool, domain_setting_serve_protocol_http: bool,
#[serde(default)] #[serde(default)]
#[serde(deserialize_with = "deserialize_bool")]
domain_setting_serve_protocol_https: bool, domain_setting_serve_protocol_https: bool,
} }