Skip to content

Commit

Permalink
JsonEncode(): serialize integers w/o trailing .0
Browse files Browse the repository at this point in the history
... so Icinga DB can parse them as integers.
  • Loading branch information
Al2Klimov committed Mar 23, 2021
1 parent 9830dc1 commit 7b04538
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/base/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/utility.hpp"
#include <bitset>
#include <boost/exception_ptr.hpp>
#include <cmath>
#include <cstdint>
#include <json.hpp>
#include <stack>
Expand Down Expand Up @@ -365,7 +366,17 @@ inline
void JsonEncoder<prettyPrint>::NumberFloat(double value)
{
BeforeItem();
AppendJson(value);

if (floor(value) == value) {
// Make sure 0.0 is serialized as 0, so Icinga DB can parse it as int.
if (value < 0) {
AppendJson((long long)value);
} else {
AppendJson((unsigned long long)value);
}
} else {
AppendJson(value);
}
}

template<bool prettyPrint>
Expand Down

0 comments on commit 7b04538

Please sign in to comment.