mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2024-12-22 14:05:18 +00:00
core: correctly serialize JSON objects
On startup, the DeviceProfile would not be serialized properly to a false assumption that QJsonValue.toString() returns the JSON representation of the given value. This now has been fixed by creating a QJsonDocument converting it to a string.
This commit is contained in:
parent
90db983c30
commit
852e3e928f
|
@ -22,6 +22,7 @@
|
|||
#include <QtGlobal>
|
||||
#include <QDateTime>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QList>
|
||||
|
@ -147,7 +148,17 @@ QString toString(const T &source) {
|
|||
|
||||
template <typename T>
|
||||
QString toString(const T &source, convertType<T>) {
|
||||
return toJsonValue(source).toString();
|
||||
QJsonValue val = toJsonValue(source);
|
||||
const QJsonDocument::JsonFormat format = QJsonDocument::Compact;
|
||||
switch(val.type()) {
|
||||
case QJsonValue::Array:
|
||||
return QJsonDocument(val.toArray()).toJson(format);
|
||||
case QJsonValue::Object:
|
||||
return QJsonDocument(val.toObject()).toJson(format);
|
||||
case QJsonValue::Null:
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
Loading…
Reference in a new issue