Nested Structure Variant with Deduction of Tagged Object Types #1246
-
I had a look at variant_handling example, but wasn't able to go around in the case of nested structure. My structure looks something like this and I have no idea how to access a member of the substructure when declaring tag as struct common_struct {
std::string key;
std::string value;
};
struct info_struct_a {
std::string a;
std::string b;
};
struct info_struct_b {
float c;
int d;
};
struct data_a {
common_struct info_common;
std::vector<info_struct_a> info;
};
struct data_b {
common_struct info_common;
std::vector<info_struct_b> info;
int other_id;
};
using data_variant = std::variant<data_a, data_b>;
template<>
struct glz::meta<data_variant> {
static constexpr std::string_view tag = "info_common.key"; // TODO: substructure's member as tag
static constexpr auto ids = std::array{"a", "b"};
}; I also tried using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Can you provide an example input JSON document for this structure that you are trying to decode? Is the |
Beta Was this translation helpful? Give feedback.
Thanks for the additional details.
Glaze cannot decode variants from sub-keys. Support may be added in the future, but I'm wary about adding too much complexity to variant handling, which is already complex. However, there are various solutions to this problem.
Note that you can still use a …