#ifndef JELLYFIN_SUPPORT_JSONCONV_H #define JELLYFIN_SUPPORT_JSONCONV_H #include #include #include #include #include #include #include #include namespace Jellyfin { namespace Support { // Helper functions QString uuidToString(const QUuid &source); QUuid stringToUuid(const QString &source); /** * @brief Thrown when JSON cannot be parsed. */ class ParseException : public std::runtime_error { public: explicit ParseException(const char *message) : std::runtime_error(message) {} }; /** * Template for converting types from JSON into their respective type. */ template T fromJsonValue(const QJsonValue &source) { Q_UNUSED(source) Q_ASSERT_X(false, "fromJsonValue", "fromJsonValue called with unimplemented type"); } template QJsonValue toJsonValue(const T &source) { Q_UNUSED(source) Q_ASSERT_X(false, "toJsonValue", "toJsonValue called with unimplemented type"); } // QList template QList fromJsonValue(const QJsonArray &source) { QList result; result.reserve(source.size()); for (auto it = source.cbegin(); it != source.cend(); it++) { result.append(fromJsonValue(*it)); } return result; } template QJsonValue toJsonValue(const QList &source) { QJsonArray result; for (auto it = source.cbegin(); it != source.cend(); it++) { result.push_back(*it); } return result; } } } #endif // JSONCONV_H