Skip to content

Commit

Permalink
fix: Fixed a bug where serialize didn't write out empty vectors and m…
Browse files Browse the repository at this point in the history
…appings in a correct way (#456)

* fix: Fixed a bug where serialize didn't write out empty vectors and mappings in a correct way. I have not added a test case, but I tested it in my code and it behaved as expected. Adding a test case at some point would be good.
  • Loading branch information
johan-gson authored Jan 6, 2025
1 parent 859389e commit c15d671
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/fkYAML/detail/output/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ class basic_serializer {
serialize_node(seq_item, cur_indent, str);
str += "\n";
}
else if (seq_item.is_sequence() && seq_item.size() == 0) {
str += " []\n";
}
else if (seq_item.is_mapping() && seq_item.size() == 0) {
str += " {}\n";
}
else {
str += "\n";
serialize_node(seq_item, cur_indent + 2, str);
Expand Down Expand Up @@ -207,6 +213,12 @@ class basic_serializer {
serialize_node(*itr, cur_indent, str);
str += "\n";
}
else if (itr->is_sequence() && itr->size() == 0) {
str += " []\n";
}
else if (itr->is_mapping() && itr->size() == 0) {
str += " {}\n";
}
else {
str += "\n";
serialize_node(*itr, cur_indent + 2, str);
Expand Down

0 comments on commit c15d671

Please sign in to comment.