From 81376458acfe0d570c098e46ae3241b78dfaf1f6 Mon Sep 17 00:00:00 2001 From: pythonology Date: Sat, 29 Jun 2019 23:38:34 -0400 Subject: [PATCH] serialization: Fix loading of empty vectors in the XML serializer --- src/serialization/XmlSerializer.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/serialization/XmlSerializer.cpp b/src/serialization/XmlSerializer.cpp index 622ebbe..5437477 100644 --- a/src/serialization/XmlSerializer.cpp +++ b/src/serialization/XmlSerializer.cpp @@ -66,6 +66,17 @@ namespace serialization void XmlSerializer::save_property(rapidxml::xml_node<> *object, const pclass::IProperty& prop) { auto *property_name = m_document.allocate_string(prop.get_name().data()); + + // Write an empty property if we don't have any elements. + if (prop.get_element_count() == 0) + { + auto *property_node = m_document.allocate_node( + rapidxml::node_element, property_name + ); + object->append_node(property_node); + return; + } + for (std::size_t i = 0; i < prop.get_element_count(); ++i) { auto *property_node = m_document.allocate_node( @@ -182,6 +193,14 @@ namespace serialization auto *key_attribute = property_node->first_attribute("key"); if (!key_attribute) { + // Perhaps this is an empty vector + if (prop.is_dynamic()) + { + property_node = property_node->next_sibling(property_name); + if (!property_node) + break; + } + std::ostringstream oss; oss << "Parameter element '" << prop.get_name() << "' is missing 'key' attribute.";