mirror of https://github.com/SeanOMik/libki.git
serialization: Fix loading of empty vectors in the XML serializer
This commit is contained in:
parent
5a0ec6f2d7
commit
81376458ac
|
@ -66,6 +66,17 @@ namespace serialization
|
||||||
void XmlSerializer::save_property(rapidxml::xml_node<> *object, const pclass::IProperty& prop)
|
void XmlSerializer::save_property(rapidxml::xml_node<> *object, const pclass::IProperty& prop)
|
||||||
{
|
{
|
||||||
auto *property_name = m_document.allocate_string(prop.get_name().data());
|
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)
|
for (std::size_t i = 0; i < prop.get_element_count(); ++i)
|
||||||
{
|
{
|
||||||
auto *property_node = m_document.allocate_node(
|
auto *property_node = m_document.allocate_node(
|
||||||
|
@ -182,6 +193,14 @@ namespace serialization
|
||||||
auto *key_attribute = property_node->first_attribute("key");
|
auto *key_attribute = property_node->first_attribute("key");
|
||||||
if (!key_attribute)
|
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;
|
std::ostringstream oss;
|
||||||
oss << "Parameter element '" << prop.get_name()
|
oss << "Parameter element '" << prop.get_name()
|
||||||
<< "' is missing 'key' attribute.";
|
<< "' is missing 'key' attribute.";
|
||||||
|
|
Loading…
Reference in New Issue