From d13358b71ec15085f2638fd9c3fc634df62dfc94 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 9 May 2021 13:56:46 -0400 Subject: Reduced dependency on json-related hacks --- src/jsonable.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/jsonable.h') 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 +#include class Jsonable { public: @@ -7,3 +9,18 @@ class Jsonable { operator nlohmann::json() const {return toJson();} virtual ~Jsonable() {} }; + +namespace nlohmann { + template struct adl_serializer> { + static void to_json(json& j, const std::shared_ptr& opt) { + if(opt) { + j = *opt; + } else { + j = nullptr; + } + } + static void from_json(const json& j, std::shared_ptr& opt) { + opt = std::shared_ptr(T::create(j)); + } + }; +} -- cgit v1.2.3