#pragma once #include "json.hpp" #include #include class Jsonable { public: virtual nlohmann::json toJson(void) const = 0; 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)); } }; }