|
|
|
|
@ -74,20 +74,10 @@ public:
|
|
|
|
|
} |
|
|
|
|
return nlohmann::json(nullptr); |
|
|
|
|
} |
|
|
|
|
static bool has_property(const std::string &key, const nlohmann::json &object) { |
|
|
|
|
auto it = object.find(key); |
|
|
|
|
return it != object.end(); |
|
|
|
|
} |
|
|
|
|
template <class T> |
|
|
|
|
static auto get(const std::string &key, const nlohmann::json &object, const T &default_value) { |
|
|
|
|
if (has_property(key, object)) { |
|
|
|
|
T r; |
|
|
|
|
try { |
|
|
|
|
r = object[key]; //TODO fix use json parser where a non-throwable exist
|
|
|
|
|
} catch (const std::exception &) { |
|
|
|
|
return default_value; |
|
|
|
|
} |
|
|
|
|
return r; |
|
|
|
|
static T get(const std::string &key, const nlohmann::json &object, const T &default_value) { |
|
|
|
|
if (object.find(key) != object.end()) { |
|
|
|
|
return object[key]; |
|
|
|
|
} |
|
|
|
|
return default_value; |
|
|
|
|
} |
|
|
|
|
|