mirror of https://github.com/SeanOMik/libki.git
serialization: Fix issue with empty arrays in JsonSerializer
This commit is contained in:
parent
680d378002
commit
7aca9ceda5
|
@ -52,6 +52,13 @@ namespace serialization
|
||||||
void JsonSerializer::save_property(
|
void JsonSerializer::save_property(
|
||||||
json &j, const pclass::IProperty &prop) const
|
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)
|
for (std::size_t i = 0; i < prop.get_element_count(); ++i)
|
||||||
{
|
{
|
||||||
if (prop.get_type().get_kind() == pclass::Type::Kind::CLASS)
|
if (prop.get_type().get_kind() == pclass::Type::Kind::CLASS)
|
||||||
|
|
|
@ -65,9 +65,9 @@ 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());
|
||||||
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_name = m_document.allocate_string(prop.get_name().data());
|
|
||||||
auto *property_node = m_document.allocate_node(
|
auto *property_node = m_document.allocate_node(
|
||||||
rapidxml::node_element, property_name
|
rapidxml::node_element, property_name
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue