refs #879, added static fromJson

This commit is contained in:
Klaus Basan
2017-02-12 22:31:31 +01:00
committed by Mathew Sutcliffe
parent d997ec1e30
commit 9b56c5bf51

View File

@@ -396,6 +396,24 @@ namespace BlackMisc
convertFromJson(BlackMisc::Json::jsonObjectFromString(jsonString));
}
//! Get object from QJsonObject
template<class DerivedObj = Derived>
static DerivedObj fromJson(const QJsonObject &json)
{
DerivedObj obj;
obj.convertFromJson(json);
return obj;
}
//! Get object from JSON string
template<class DerivedObj = Derived>
static DerivedObj fromJson(const QString &jsonString)
{
DerivedObj obj;
obj.convertFromJson(BlackMisc::Json::jsonObjectFromString(jsonString));
return obj;
}
private:
const Derived *derived() const { return static_cast<const Derived *>(this); }
Derived *derived() { return static_cast<Derived *>(this); }