mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
refs #815 Throw CJsonException when required JSON objects are not found.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/inheritancetraits.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/jsonexception.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QJsonArray>
|
||||
@@ -375,8 +376,17 @@ namespace BlackMisc
|
||||
auto meta = introspect<Derived>().without(MetaFlags<DisabledForJson>());
|
||||
meta.forEachMemberName(*derived(), [ & ](auto & member, CExplicitLatin1String name)
|
||||
{
|
||||
auto it = json.find(name);
|
||||
if (it != json.end()) { it.value() >> member; }
|
||||
const auto value = json.value(name);
|
||||
if (value.isUndefined())
|
||||
{
|
||||
constexpr bool required = false; // \todo add RequiredForJson flag in metaclass system
|
||||
if (required) { throw CJsonException(QStringLiteral("Missing required member '%1'").arg(name.m_latin1)); }
|
||||
}
|
||||
else
|
||||
{
|
||||
CJsonScope scope(name.m_latin1);
|
||||
value >> member;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user