diff --git a/code/json/marshaling.hxx b/code/json/marshaling.hxx index 4a2d395..c8f60eb 100644 --- a/code/json/marshaling.hxx +++ b/code/json/marshaling.hxx @@ -260,6 +260,46 @@ namespace code::json }; + template + struct emplace_member_t + { + using T = Type; + + static constexpr bool is_optional{ + is_optional_v + }; + + static + T + unmarshal(variant const& v, marshaling_context_t* context) + { + if (!v.contains(Name.str())) { + if constexpr (is_optional) { + return std::nullopt; + } + + throw std::runtime_error{"missing field '" + Name.str() + "'"}; + } + + return marshaling_traits::unmarshal(v.get(Name), context); + } + + }; + + template + struct emplace_t + { + static + T + unmarshal(variant const& v, marshaling_context_t* context) + { + return T{ + Members::unmarshal(v, context)... + }; + } + + }; + template struct marshaling_traits {