diff --git a/iguana/json_reader.hpp b/iguana/json_reader.hpp index 1597d93b..6a86025b 100644 --- a/iguana/json_reader.hpp +++ b/iguana/json_reader.hpp @@ -499,6 +499,14 @@ IGUANA_INLINE void skip_object_value(It &&it, It &&end) { } } +template , int> = 0> +IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { + std::visit( + [&](auto &val) { + from_json_impl(val, it, end); + }, + value); +} } // namespace detail template , int>> diff --git a/test/test.cpp b/test/test.cpp index 568bd5d2..79b5240a 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,6 +1,8 @@ #include #include #include + +#include "iguana/reflection.hpp" #define DOCTEST_CONFIG_IMPLEMENT #include #include @@ -161,6 +163,33 @@ void get_value_test_helper(const std::string &json_str, const T &expect) { CHECK(actual == expect); } +namespace my_space { +struct inner_struct { + int x; + int y; + int z; +}; +REFLECTION(inner_struct, x, y, z); +} // namespace my_space + +struct nest_t { + std::string name; + my_space::inner_struct value; + std::variant var; +}; +REFLECTION(nest_t, name, value, var); + +TEST_CASE("test variant") { + std::variant var; + var = 1; + nest_t v{"Hi", {1, 2, 3}, var}, v2; + std::string s; + iguana::to_json(v, s); + std::cout << s << std::endl; + iguana::from_json(v2, s); + CHECK(v.name == v2.name); +} + TEST_CASE("test from issues") { test test1{}; std::string str1 =