25 #include <boost/lexical_cast.hpp> 28 #include <type_traits> 70 std::string str = j.get<std::string>();
71 uuid =
Leosac::UUID(boost::lexical_cast<boost::uuids::uuid>(str));
73 else if (j.is_number_unsigned() && j.get<uint64_t>() == 0)
104 template <
typename T>
105 typename std::enable_if<!std::is_same<const char *, T>::value &&
106 !std::is_same<std::chrono::system_clock::time_point,
107 std::remove_reference_t<T>>::value &&
108 !std::is_enum<T>::value,
113 T ret = default_value;
116 if (!obj.at(key).is_null())
117 ret = obj.at(key).get<T>();
119 catch (
const json::out_of_range &e)
125 template <
typename T>
126 typename std::enable_if<std::is_enum<T>::value, T>::type
130 T ret = default_value;
133 if (!obj.at(key).is_null())
136 ret =
static_cast<T
>(obj.at(key).get<std::underlying_type_t<T>>());
139 catch (
const json::out_of_range &e)
145 template <
typename T>
146 typename std::enable_if<std::is_same<const char *, T>::value, std::string>::type
150 return extract_with_default<std::string>(obj, key, default_value);
157 std::chrono::system_clock::time_point
159 const std::chrono::system_clock::time_point &tp);
170 const std::string &base_key,
This is the header file for a generated source file, GitSHA1.cpp.
A simple class that stores (and can be queried for) the validity of some objects. ...
Below we add a serializer into the nlohmann namespace to serialize the Leosac::UUID ype...
Thin wrapper around boost::uuids::uuid.
Exception class for LEOSAC Project related errors.
static void to_json(json &j, const Leosac::UUID &uuid)
A base class for Leosac specific exception.
static void from_json(const json &j, Leosac::UUID &uuid)
For unserialization we expect either a string representing the UUID, or a number. ...
Auth::ValidityInfo extract_validity_with_default(const nlohmann::json &obj, const std::string &base_key, const Auth::ValidityInfo &def)
Extract fields representing a ValidityInfo object.
std::string to_string() const
std::enable_if< std::is_same< const char *, T >::value, std::string >::type extract_with_default(const nlohmann::json &obj, const std::string &key, T default_value)
static UUID null_uuid()
Returns a null UUID with a full zero value.