diff options
author | Your Name <you@example.com> | 2021-05-09 13:56:46 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-05-09 13:56:46 -0400 |
commit | d13358b71ec15085f2638fd9c3fc634df62dfc94 (patch) | |
tree | 467c643a068bf2d83da3632823a6434244ae004e /src/jsonable.h | |
parent | e3aaa68a2ea1a403256150121c57a0287014162f (diff) | |
download | dmtool-d13358b71ec15085f2638fd9c3fc634df62dfc94.tar.gz dmtool-d13358b71ec15085f2638fd9c3fc634df62dfc94.tar.bz2 dmtool-d13358b71ec15085f2638fd9c3fc634df62dfc94.zip |
Reduced dependency on json-related hacks
Diffstat (limited to 'src/jsonable.h')
-rw-r--r-- | src/jsonable.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/jsonable.h b/src/jsonable.h index 7411efa..01c720b 100644 --- a/src/jsonable.h +++ b/src/jsonable.h @@ -1,5 +1,7 @@ #pragma once #include "json.hpp" +#include <memory> +#include <vector> class Jsonable { public: @@ -7,3 +9,18 @@ class Jsonable { operator nlohmann::json() const {return toJson();} virtual ~Jsonable() {} }; + +namespace nlohmann { + template <typename T> struct adl_serializer<std::shared_ptr<T>> { + static void to_json(json& j, const std::shared_ptr<T>& opt) { + if(opt) { + j = *opt; + } else { + j = nullptr; + } + } + static void from_json(const json& j, std::shared_ptr<T>& opt) { + opt = std::shared_ptr<T>(T::create(j)); + } + }; +} |