serialization: Fix issue with empty arrays in JsonSerializer

This commit is contained in:
Joshua Scott 2019-01-21 12:27:55 +00:00
parent 680d378002
commit 7aca9ceda5
2 changed files with 14 additions and 7 deletions

View File

@ -52,6 +52,13 @@ namespace serialization
void JsonSerializer::save_property(
json &j, const pclass::IProperty &prop) const
{
// Ensure that, even if there is no value, the property is added
// to the JSON object
if (prop.is_array())
j[prop.get_name()] = std::vector<json>();
else
j[prop.get_name()] = json();
for (std::size_t i = 0; i < prop.get_element_count(); ++i)
{
if (prop.get_type().get_kind() == pclass::Type::Kind::CLASS)

View File

@ -65,9 +65,9 @@ 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());
for (std::size_t i = 0; i < prop.get_element_count(); ++i)
{
auto *property_name = m_document.allocate_string(prop.get_name().data());
auto *property_node = m_document.allocate_node(
rapidxml::node_element, property_name
);