diff --git a/include/Support/JSON.h b/include/Support/JSON.h index dffe70bf..a1189246 100644 --- a/include/Support/JSON.h +++ b/include/Support/JSON.h @@ -70,6 +70,20 @@ struct Serde { } }; +template +struct Serde> { + static json::Value serialize(const std::optional& v) { + return v ? json::serialize(*v) : json::Value(nullptr); + } + + static std::optional deserialize(const json::Value& value) { + if(value.kind() == json::Value::Null) { + return std::nullopt; + } + return json::deserialize(value); + } +}; + template <> struct Serde { static json::Value serialize(bool v) {