summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonwriter.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-10-21 10:26:45 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-11-05 10:12:04 +0100
commitedec095cf80b62057116ce75c581b5ca5866bdcc (patch)
treea849983cff625c80f9386865988f32ad552837cd /src/corelib/serialization/qjsonwriter.cpp
parente99b0016e8b639e40d5330e0c3eaa199b48e34f4 (diff)
Fix 64-bit integer support in QtJSON
Fixes parsing writing and pass-through of integers with higher precision than double can handle. Note this adds extra precision compared to JavaScript, but the JSON files read and written this way are still valid, and the extra precision in reading and writing this way is used by many JSON libraries. Fixes: QTBUG-28560 Change-Id: I30b2415c928d1c34c8cb4e4c6218602095e7e8aa Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qjsonwriter.cpp')
-rw-r--r--src/corelib/serialization/qjsonwriter.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/corelib/serialization/qjsonwriter.cpp b/src/corelib/serialization/qjsonwriter.cpp
index 627d1bbd62..31fb16c112 100644
--- a/src/corelib/serialization/qjsonwriter.cpp
+++ b/src/corelib/serialization/qjsonwriter.cpp
@@ -138,15 +138,14 @@ static void valueToJson(const QCborValue &v, QByteArray &json, int indent, bool
json += "false";
break;
case QCborValue::Integer:
+ json += QByteArray::number(v.toInteger());
+ break;
case QCborValue::Double: {
const double d = v.toDouble();
- if (qIsFinite(d)) {
- quint64 absInt;
- json += QByteArray::number(d, convertDoubleTo(std::abs(d), &absInt) ? 'f' : 'g',
- QLocale::FloatingPointShortest);
- } else {
+ if (qIsFinite(d))
+ json += QByteArray::number(d, 'g', QLocale::FloatingPointShortest);
+ else
json += "null"; // +INF || -INF || NaN (see RFC4627#section2.4)
- }
break;
}
case QCborValue::String: