diff --git a/src/designspace.rs b/src/designspace.rs index 7f5d26c5..7803e564 100644 --- a/src/designspace.rs +++ b/src/designspace.rs @@ -29,7 +29,7 @@ pub struct DesignSpaceDocument { #[serde(default, with = "serde_impls::instances", skip_serializing_if = "Vec::is_empty")] pub instances: Vec, /// Additional arbitrary user data - #[serde(default, with = "serde_plist")] + #[serde(default, with = "serde_plist", skip_serializing_if = "Dictionary::is_empty")] pub lib: Dictionary, } @@ -140,7 +140,7 @@ pub struct Instance { #[serde(with = "serde_impls::location")] pub location: Vec, /// Arbitrary data about this instance - #[serde(default, with = "serde_plist")] + #[serde(default, with = "serde_plist", skip_serializing_if = "Dictionary::is_empty")] pub lib: Dictionary, } @@ -389,6 +389,15 @@ mod tests { ); } + #[test] + fn do_not_serialize_empty_lib() { + let ds_initial = DesignSpaceDocument::load("testdata/single_wght.designspace").unwrap(); + let serialized = quick_xml::se::to_string(&ds_initial).expect("should serialize"); + + assert!(!serialized.contains("")); + assert!(!serialized.contains("")); + } + #[test] fn load_save_round_trip() { // Given