diff --git a/include/rfl/json/Reader.hpp b/include/rfl/json/Reader.hpp index ac86ad84..68d8e614 100644 --- a/include/rfl/json/Reader.hpp +++ b/include/rfl/json/Reader.hpp @@ -88,7 +88,8 @@ struct Reader { yyjson_obj_iter_init(_obj.val_, &iter); yyjson_val* key; while ((key = yyjson_obj_iter_next(&iter))) { - const auto name = std::string_view(yyjson_get_str(key), yyjson_get_len(key)); + const auto name = + std::string_view(yyjson_get_str(key), yyjson_get_len(key)); _object_reader.read(name, InputVarType(yyjson_obj_iter_get_val(key))); } return std::nullopt; @@ -116,8 +117,8 @@ struct Reader { return static_cast(yyjson_get_num(_var.val_)); } else if constexpr (std::is_unsigned>()) { - if (!yyjson_is_int(_var.val_)) { - return error("Could not cast to int."); + if (!yyjson_is_uint(_var.val_)) { + return error("Could not cast to uint."); } return static_cast(yyjson_get_uint(_var.val_)); diff --git a/tests/json/test_atomic_negative.cpp b/tests/json/test_atomic_negative.cpp new file mode 100644 index 00000000..cb0e3ec3 --- /dev/null +++ b/tests/json/test_atomic_negative.cpp @@ -0,0 +1,26 @@ +#include + +#include +#include +#include +#include + +namespace test_atomic_negative { + +struct TestObject { + std::uint64_t number{0}; +}; + +struct AtomicTestObject { + std::atomic number{0}; +}; + +TEST(json, test_atomic_negative) { + auto req1 = rfl::json::read(R"({"number": -1})"); + EXPECT_FALSE(req1.has_value()); + + auto req2 = rfl::json::read>(R"({"number": -1})"); + EXPECT_FALSE(req2.has_value()); +} + +} // namespace test_atomic_negative