diff --git a/sarif/include/gap/sarif/sarif.hpp b/sarif/include/gap/sarif/sarif.hpp index fc5649b..6356bc6 100644 --- a/sarif/include/gap/sarif/sarif.hpp +++ b/sarif/include/gap/sarif/sarif.hpp @@ -24,6 +24,44 @@ #include +NLOHMANN_JSON_NAMESPACE_BEGIN + + 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 = nullptr; + else + j = *opt; + } + + static std::shared_ptr< T > from_json(const json &j) { + if (j.is_null()) + return std::make_shared< T >(); + else + return std::make_shared< T >(j.get< T >()); + } + }; + + template< typename T > + struct adl_serializer< std::optional< T > > { + static void to_json(json &j, const std::optional< T > &opt) { + if (!opt) + j = nullptr; + else + j = *opt; + } + + static std::optional< T > from_json(const json &j) { + if (j.is_null()) + return std::nullopt; + else + return std::make_optional< T >(j.get< T >()); + } + }; + +NLOHMANN_JSON_NAMESPACE_END + namespace gap::sarif { using json = nlohmann::json;