From 852e3e928f12ed59313761668f52b9f26530222d Mon Sep 17 00:00:00 2001 From: Henk Kalkwater Date: Mon, 25 Oct 2021 16:10:36 +0200 Subject: [PATCH] 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. --- core/include/JellyfinQt/support/jsonconvimpl.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/include/JellyfinQt/support/jsonconvimpl.h b/core/include/JellyfinQt/support/jsonconvimpl.h index e6dd422..5f77c9d 100644 --- a/core/include/JellyfinQt/support/jsonconvimpl.h +++ b/core/include/JellyfinQt/support/jsonconvimpl.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -147,7 +148,17 @@ QString toString(const T &source) { template QString toString(const T &source, convertType) { - 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