Add some missing field checks to JSON reader

This commit is contained in:
Gary Talent 2017-09-08 18:06:27 -05:00
parent 3e90ec87b9
commit 11c7c49d7b

View File

@ -59,19 +59,27 @@ class JsonReader {
template<typename T>
ox::Error JsonReader::op(QString fieldName, T *dest) {
if (m_src.contains(fieldName)) {
auto obj = m_src[fieldName].toObject();
auto reader = JsonReader(obj);
return ioOp(&reader, dest);
} else {
return JSON_ERR_FIELD_MISSING;
}
};
template<typename T>
ox::Error JsonReader::op(QString fieldName, QVector<T> *dest) {
ox::Error err = 0;
if (m_src.contains(fieldName)) {
auto a = m_src[fieldName].toArray();
dest->resize(a.size());
for (int i = 0; i < dest->size(); i++) {
err |= op(a[i], &(*dest)[i]);
}
} else {
err |= JSON_ERR_FIELD_MISSING;
}
return err;
};