aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-09 17:42:06 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-09 19:45:52 +0900
commit1678296d5b6190679a9ef950f9421945fa159f8f (patch)
tree764f43d2301cee3cac5138d978f6e38765e505b0 /lib
parentd51684b759f686b2c9895c5013dce88fead9661b (diff)
downloadlibquotient-1678296d5b6190679a9ef950f9421945fa159f8f.tar.gz
libquotient-1678296d5b6190679a9ef950f9421945fa159f8f.zip
fromJson, fillFromJson: avoid overwriting pods if the JSON value is undefined
Diffstat (limited to 'lib')
-rw-r--r--lib/converters.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/converters.h b/lib/converters.h
index 6227902d..af2be645 100644
--- a/lib/converters.h
+++ b/lib/converters.h
@@ -110,7 +110,8 @@ namespace QMatrixClient
template <typename T>
inline void fromJson(const QJsonValue& jv, T& pod)
{
- pod = fromJson<T>(jv);
+ if (!jv.isUndefined())
+ pod = fromJson<T>(jv);
}
template <typename T>
@@ -123,13 +124,17 @@ namespace QMatrixClient
template <typename T>
inline void fromJson(const QJsonValue& jv, Omittable<T>& pod)
{
- pod = fromJson<T>(jv);
+ if (jv.isUndefined())
+ pod = none;
+ else
+ pod = fromJson<T>(jv);
}
template <typename T>
inline void fillFromJson(const QJsonValue& jv, T& pod)
{
- JsonObjectConverter<T>::fillFrom(jv.toObject(), pod);
+ if (jv.isObject())
+ JsonObjectConverter<T>::fillFrom(jv.toObject(), pod);
}
// JsonConverter<> specialisations