Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/rfl/json/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,8 +117,8 @@ struct Reader {
return static_cast<T>(yyjson_get_num(_var.val_));

} else if constexpr (std::is_unsigned<std::remove_cvref_t<T>>()) {
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<T>(yyjson_get_uint(_var.val_));

Expand Down
26 changes: 26 additions & 0 deletions tests/json/test_atomic_negative.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <gtest/gtest.h>

#include <atomic>
#include <cstdint>
#include <rfl.hpp>
#include <rfl/json.hpp>

namespace test_atomic_negative {

struct TestObject {
std::uint64_t number{0};
};

struct AtomicTestObject {
std::atomic<std::uint64_t> number{0};
};

TEST(json, test_atomic_negative) {
auto req1 = rfl::json::read<TestObject>(R"({"number": -1})");
EXPECT_FALSE(req1.has_value());

auto req2 = rfl::json::read<rfl::Ref<AtomicTestObject>>(R"({"number": -1})");
EXPECT_FALSE(req2.has_value());
}

} // namespace test_atomic_negative
Loading