Skip to content

deserializing a json array of different objects. #298

Answered by mwalcott3
wenzhengresideo asked this question in Q&A
Discussion options

You must be logged in to vote

tldr use std::tuple or a meta with a glz::array value for this example case and std::vector<std::variant<ObjectTypes...>> generally. It should just work if all the objects have metas.

If the types always have the same order and length you can parse to a std::tuple of those types and it should work as long as they have metas for all the individual objects. std::tuple<Object1, Object2, std::string>. Alternatively, you can also create an array based meta instead of an object one glz::array(&T::object1, &T::object2, &T::date_time)

If the array has variable length and differing types you can create a std::vector of std::variants of the different object types https://github.com/stephenberry/gla…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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