diff --git a/include/rfl/json/read.hpp b/include/rfl/json/read.hpp index 7d3d3129..35396168 100644 --- a/include/rfl/json/read.hpp +++ b/include/rfl/json/read.hpp @@ -32,9 +32,16 @@ auto read(const InputVarType& _obj) { template Result> read( const std::string_view _json_str, const yyjson_read_flag _flag = 0) { - yyjson_doc* doc = yyjson_read(_json_str.data(), _json_str.size(), _flag); + if (_flag & YYJSON_READ_INSITU) { + return error("YYJSON_READ_INSITU is not supported"); + } + yyjson_read_err err; + // According to yyjson's doc, it's safe castaway constness as long as + // YYJSON_READ_INSITU is not set + yyjson_doc* doc = yyjson_read_opts(const_cast(_json_str.data()), + _json_str.size(), _flag, NULL, &err); if (!doc) { - return error("Could not parse document"); + return error("Could not parse document: " + std::string(err.msg)); } yyjson_val* root = yyjson_doc_get_root(doc); const auto r = Reader(); diff --git a/tests/json/test_error_messages.cpp b/tests/json/test_error_messages.cpp index bdd69a0f..4e7387a4 100644 --- a/tests/json/test_error_messages.cpp +++ b/tests/json/test_error_messages.cpp @@ -37,13 +37,13 @@ TEST(json, test_decode_error_without_exception) { R"({"firstName":"Homer";"lastName":"Simpson";"birthday":"1987-04-19"})"; rfl::Result result = rfl::error("result didn't get set"); - EXPECT_NO_THROW({ - result = rfl::json::read(faulty_string); - }); + EXPECT_NO_THROW({ result = rfl::json::read(faulty_string); }); EXPECT_TRUE(!result.has_value() && true); - EXPECT_EQ(result.error().what(), "Could not parse document"); + EXPECT_EQ(result.error().what(), + "Could not parse document: unexpected character, expected a comma " + "or a closing brace"); } } // namespace test_error_messages