Skip to content

Map flat struct to nested object #421

Discussion options

You must be logged in to vote

This will be simpler when reading is added for glz::obj, but for now here is a solution:

  • I've included my test case I added to json_tests. I had to accept rvalue objects to make this work, so I just merged #420.
struct test_mapping_t
{
    int64_t id;
    double latitude;
    double longitude;
};

struct coordinates_t
{
   double* latitude;
   double* longitude;
};

template <>
struct glz::meta<coordinates_t>
{
   using T = coordinates_t;
   static constexpr auto value = object("latitude", &T::latitude, "longitude", &T::longitude);
};

template <>
struct glz::meta<test_mapping_t>
{
   using T = test_mapping_t;
   static constexpr auto value = object("id", &T::id, "coordinates", [](auto&…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@azais-corentin
Comment options

@stephenberry
Comment options

Answer selected by stephenberry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #419 on September 01, 2023 14:35.