aboutsummaryrefslogtreecommitdiff
path: root/lib/converters.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/converters.h')
-rw-r--r--lib/converters.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/converters.h b/lib/converters.h
index 49cb1ed9..da30cae6 100644
--- a/lib/converters.h
+++ b/lib/converters.h
@@ -228,11 +228,24 @@ struct QUOTIENT_API JsonConverter<QVariant> {
template <typename... Ts>
inline QJsonValue toJson(const std::variant<Ts...>& v)
{
+ // std::visit requires all overloads to return the same type - and
+ // QJsonValue is a perfect candidate for that same type (assuming that
+ // variants never occur on the top level in Matrix API)
return std::visit(
[](const auto& value) { return QJsonValue { toJson(value) }; }, v);
}
template <typename T>
+struct QUOTIENT_API JsonConverter<std::variant<QString, T>> {
+ static std::variant<QString, T> load(const QJsonValue& jv)
+ {
+ if (jv.isString())
+ return fromJson<QString>(jv);
+ return fromJson<T>(jv);
+ }
+};
+
+template <typename T>
struct JsonConverter<Omittable<T>> {
static QJsonValue dump(const Omittable<T>& from)
{