diff --git a/include/rfl/parsing/is_required.hpp b/include/rfl/parsing/is_required.hpp index e72a3f4b..befa2545 100644 --- a/include/rfl/parsing/is_required.hpp +++ b/include/rfl/parsing/is_required.hpp @@ -5,6 +5,7 @@ #include #include +#include "../Generic.hpp" #include "../Rename.hpp" #include "../internal/StringLiteral.hpp" #include "../internal/is_rename.hpp" @@ -37,7 +38,8 @@ constexpr bool is_never_required_v = is_never_required::value; template consteval bool is_required() { using Type = std::remove_cvref_t>; - if constexpr (internal::has_reflection_type_v) { + if constexpr (internal::has_reflection_type_v && + !std::is_same_v) { return is_required(); } else if constexpr (internal::is_rename_v) { diff --git a/src/rfl/Generic.cpp b/src/rfl/Generic.cpp index 1d94a097..52ffdce0 100644 --- a/src/rfl/Generic.cpp +++ b/src/rfl/Generic.cpp @@ -28,7 +28,7 @@ SOFTWARE. namespace rfl { -Generic::Generic() : value_(false) {} +Generic::Generic() : value_(std::nullopt) {} Generic::Generic(Generic&& _other) noexcept = default; diff --git a/tests/json/test_generic2.cpp b/tests/json/test_generic2.cpp new file mode 100644 index 00000000..e16b2555 --- /dev/null +++ b/tests/json/test_generic2.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_generic2 { + +TEST(json, test_generic2) { + std::string response = + "{\"kind\":2,\"error\":\"Internal " + "error\",\"status\":101,\"stats\":{\"cpuTime\":803,\"totalTime\":1}}"; + + struct DataHolder { + int kind = 0; + rfl::Generic data; + }; + auto result = rfl::json::read(response); + + EXPECT_TRUE(!(result && true)); +} + +} // namespace test_generic2