From 097be4c012ba4618b4faf1054a864cab16d749cf Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 10 Jul 2022 21:42:48 +0200 Subject: [PATCH] Util: Fix Serializer trailing commas in Object dumping The .end() returns an iterator one past the last pair, so it would always add a comma after the last member. --- src/util/json/serializer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/json/serializer.cpp b/src/util/json/serializer.cpp index ae56d58..e724529 100644 --- a/src/util/json/serializer.cpp +++ b/src/util/json/serializer.cpp @@ -5,6 +5,7 @@ */ #include // uint32_t +#include // prev #include // ostringstream #include @@ -119,7 +120,7 @@ std::string Serializer::dumpObject(const Value& value, const uint32_t indentLeve result += dumpHelper(it->second, indentLevel + 1); // Add comma, except after the last element - if (it != members.end()) { + if (it != std::prev(members.end(), 1)) { result += ","; } if (m_indent > 0) {