From 044e4c4b2704fa214d262b03308b1d926e71e48b Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Mon, 26 Jan 2026 17:30:22 +0800 Subject: [PATCH] feat: implement serialize for optional --- include/Support/JSON.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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) {