mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +02:00
JsonEncode(): serialize integers w/o trailing .0
... so Icinga DB can parse them as integers.
This commit is contained in:
parent
9830dc194b
commit
9531de3835
@ -365,7 +365,25 @@ inline
|
|||||||
void JsonEncoder<prettyPrint>::NumberFloat(double value)
|
void JsonEncoder<prettyPrint>::NumberFloat(double value)
|
||||||
{
|
{
|
||||||
BeforeItem();
|
BeforeItem();
|
||||||
AppendJson(value);
|
|
||||||
|
// Make sure 0.0 is serialized as 0, so e.g. Icinga DB can parse it as int.
|
||||||
|
if (value < 0) {
|
||||||
|
long long i = value;
|
||||||
|
|
||||||
|
if (i == value) {
|
||||||
|
AppendJson(i);
|
||||||
|
} else {
|
||||||
|
AppendJson(value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unsigned long long i = value;
|
||||||
|
|
||||||
|
if (i == value) {
|
||||||
|
AppendJson(i);
|
||||||
|
} else {
|
||||||
|
AppendJson(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool prettyPrint>
|
template<bool prettyPrint>
|
||||||
|
@ -31,11 +31,11 @@ BOOST_AUTO_TEST_CASE(encode)
|
|||||||
],
|
],
|
||||||
"false": false,
|
"false": false,
|
||||||
"float": -1.25,
|
"float": -1.25,
|
||||||
"int": -42.0,
|
"int": -42,
|
||||||
"null": null,
|
"null": null,
|
||||||
"string": "LF\nTAB\tAUml\u00e4Ill\ufffd",
|
"string": "LF\nTAB\tAUml\u00e4Ill\ufffd",
|
||||||
"true": true,
|
"true": true,
|
||||||
"uint": 23.0
|
"uint": 23
|
||||||
}
|
}
|
||||||
)EOF");
|
)EOF");
|
||||||
|
|
||||||
@ -55,11 +55,11 @@ BOOST_AUTO_TEST_CASE(decode)
|
|||||||
],
|
],
|
||||||
"false": false,
|
"false": false,
|
||||||
"float": -1.25,
|
"float": -1.25,
|
||||||
"int": -42.0,
|
"int": -42,
|
||||||
"null": null,
|
"null": null,
|
||||||
"string": "LF\nTAB\tAUmlIll",
|
"string": "LF\nTAB\tAUmlIll",
|
||||||
"true": true,
|
"true": true,
|
||||||
"uint": 23.0
|
"uint": 23
|
||||||
}
|
}
|
||||||
)EOF");
|
)EOF");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user