mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #879, added static fromJson
This commit is contained in:
committed by
Mathew Sutcliffe
parent
d997ec1e30
commit
9b56c5bf51
@@ -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); }
|
||||
|
||||
Reference in New Issue
Block a user