feat: implement serialize for optional

This commit is contained in:
Myriad-Dreamin
2026-01-26 17:30:22 +08:00
parent 68eb63ba04
commit 044e4c4b27

View File

@@ -70,6 +70,20 @@ struct Serde<std::nullopt_t> {
}
};
template <typename T>
struct Serde<std::optional<T>> {
static json::Value serialize(const std::optional<T>& v) {
return v ? json::serialize(*v) : json::Value(nullptr);
}
static std::optional<T> deserialize(const json::Value& value) {
if(value.kind() == json::Value::Null) {
return std::nullopt;
}
return json::deserialize<T>(value);
}
};
template <>
struct Serde<bool> {
static json::Value serialize(bool v) {