// Copyright (c) 2019, QuantStack and Mamba Contributors // // Distributed under the terms of the BSD 3-Clause License. // // The full license is in the file LICENSE, distributed with this software. #ifndef MAMBA_UTIL_JSON_HPP #define MAMBA_UTIL_JSON_HPP #include NLOHMANN_JSON_NAMESPACE_BEGIN template struct adl_serializer> { static void to_json(json& j, const std::optional& opt) { if (opt.has_value()) { j = opt.value(); } else { j = nullptr; } } static void from_json(const json& j, std::optional& opt) { if (!j.is_null()) { opt = j.template get(); } else { opt = std::nullopt; } } }; NLOHMANN_JSON_NAMESPACE_END namespace mamba::util { template void deserialize_maybe_missing(Json&& j, const char (&name)[N], T& t) { if (j.contains(name)) { t = std::forward(j)[name].template get(); } else { t = {}; } } } #endif