diff --git a/include/rfl/parsing/Parser_tagged_union.hpp b/include/rfl/parsing/Parser_tagged_union.hpp index 8821dc5c..7fd5c326 100644 --- a/include/rfl/parsing/Parser_tagged_union.hpp +++ b/include/rfl/parsing/Parser_tagged_union.hpp @@ -154,18 +154,13 @@ struct Parser, return Error(stream.str()); }; - if constexpr (no_field_names_) { - using T = tagged_union_wrapper_no_ptr_t), AlternativeType>>; - *_result = Parser::read(_r, _var) - .transform(get_fields) - .transform(to_tagged_union) - .transform_error(embellish_error); - } else { - *_result = Parser::read(_r, _var) - .transform(to_tagged_union) - .transform_error(embellish_error); - } + using T = tagged_union_wrapper_no_ptr_t), AlternativeType>>; + + *_result = Parser::read(_r, _var) + .transform(get_fields) + .transform(to_tagged_union) + .transform_error(embellish_error); *_match_found = true; } diff --git a/tests/json/test_tagged_union_with_no_extra_fields.cpp b/tests/json/test_tagged_union_with_no_extra_fields.cpp new file mode 100644 index 00000000..e2b2bc5c --- /dev/null +++ b/tests/json/test_tagged_union_with_no_extra_fields.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_tagged_union_with_no_extra_fields { + +struct Circle { + double radius; +}; + +struct Rectangle { + double height; + double width; +}; + +struct Square { + double width; +}; + +using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; + +TEST(json, test_tagged_union_with_no_extra_fields) { + const Shapes r = Rectangle{.height = 10, .width = 5}; + + write_and_read( + r, R"({"shape":"Rectangle","height":10.0,"width":5.0})"); +} +} // namespace test_tagged_union_with_no_extra_fields