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:
Chris Josten 2021-10-25 16:10:36 +02:00
parent 90db983c30
commit 852e3e928f
1 changed files with 12 additions and 1 deletions

View File

@ -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>