// Copyright 2020 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include namespace app { template void extract( boost::json::object const & obj, char const * name, T & value ) { value = boost::json::value_to( obj.at( name ) ); } template, class D2 = boost::describe::describe_members, class En = std::enable_if_t::value && !std::is_union::value> > T tag_invoke( boost::json::value_to_tag const&, boost::json::value const& v ) { auto const& obj = v.as_object(); T t{}; boost::mp11::mp_for_each([&](auto D){ extract( obj, D.name, t.*D.pointer ); }); return t; } struct A { int x; int y; }; BOOST_DESCRIBE_STRUCT(A, (), (x, y)) } // namespace app #include int main() { boost::json::value jv{ { "x", 1 }, { "y", 2 } }; std::cout << "jv: " << jv << std::endl; auto a = boost::json::value_to( jv ); std::cout << "a: { " << a.x << ", " << a.y << " }" << std::endl; }