diff --git a/src/api/common/xml/website.rs b/src/api/common/xml/website.rs index a3889cda..f0c0d596 100644 --- a/src/api/common/xml/website.rs +++ b/src/api/common/xml/website.rs @@ -10,11 +10,14 @@ use crate::xml::{xmlns_tag, IntValue, Value}; pub struct WebsiteConfiguration { #[serde(rename = "@xmlns", serialize_with = "xmlns_tag", skip_deserializing)] pub xmlns: (), - #[serde(rename = "ErrorDocument")] + #[serde(rename = "ErrorDocument", skip_serializing_if = "Option::is_none")] pub error_document: Option, - #[serde(rename = "IndexDocument")] + #[serde(rename = "IndexDocument", skip_serializing_if = "Option::is_none")] pub index_document: Option, - #[serde(rename = "RedirectAllRequestsTo")] + #[serde( + rename = "RedirectAllRequestsTo", + skip_serializing_if = "Option::is_none" + )] pub redirect_all_requests_to: Option, #[serde( rename = "RoutingRules", @@ -400,4 +403,21 @@ mod tests { assert_eq!(unprettify_xml(message), unprettify_xml(&message2)); } + + #[test] + fn test_serialize_empty() { + let conf = WebsiteConfiguration { + xmlns: (), + error_document: None, + index_document: None, + redirect_all_requests_to: None, + routing_rules: RoutingRules { rules: vec![] }, + }; + let serialized_ref = r#" + +"#; + + let serialized = to_xml_with_header(&conf).expect("xml serialization"); + assert_eq!(unprettify_xml(&serialized), unprettify_xml(&serialized_ref)); + } }