diff --git a/code/json/marshaling.hxx b/code/json/marshaling.hxx index 0e12bbc..9a2f539 100644 --- a/code/json/marshaling.hxx +++ b/code/json/marshaling.hxx @@ -140,24 +140,42 @@ namespace code::json }; - template + template struct mapping_t { + using T = First::T; + + static + void + do_marshal(variant& v, T const& instance, marshaling_context_t* context) + { + First::marshal(v, instance, context); + ((Members::marshal(v, instance, context)), ...); + } + static variant marshal(T const& instance, marshaling_context_t* context) { variant v{std::map{}}; - ((Members::marshal(v, instance, context)), ...); + do_marshal(v, instance, context); return v; } + static + void + do_unmarshal(T& instance, variant const& v, marshaling_context_t* context) + { + First::unmarshal(instance, v, context); + ((Members::unmarshal(instance, v, context)), ...); + } + static T unmarshal(variant const& v, marshaling_context_t* context) { T instance; - ((Members::unmarshal(instance, v, context)), ...); + do_unmarshal(instance, v, context); return instance; } diff --git a/code/json/marshaling.test.cxx b/code/json/marshaling.test.cxx index 50ac03b..3edc1c8 100644 --- a/code/json/marshaling.test.cxx +++ b/code/json/marshaling.test.cxx @@ -26,7 +26,6 @@ struct name_t std::string last; using json = mapping_t< - name_t, member_t<"/person/first", &name_t::first>::pointer_t, member_t<"/person/last", &name_t::last>::pointer_t >; diff --git a/code/json/serialize.test.cxx b/code/json/serialize.test.cxx index c72b9ce..97f0ae1 100644 --- a/code/json/serialize.test.cxx +++ b/code/json/serialize.test.cxx @@ -18,7 +18,6 @@ struct person_name { std::string last; using json = mapping_t< - person_name, member_t<"first", &person_name::first>, member_t<"last", &person_name::last> >; @@ -30,7 +29,6 @@ struct person { int age; using json = mapping_t< - person, member_t<"name", &person::name>, member_t<"age", &person::age> >;