diff --git a/iguana/json_reader.hpp b/iguana/json_reader.hpp index 768610dc..8e26b42d 100644 --- a/iguana/json_reader.hpp +++ b/iguana/json_reader.hpp @@ -450,8 +450,6 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { template , int> = 0> IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { skip_ws(it, end); - if (it < end && *it == '"') - IGUANA_LIKELY { ++it; } using T = std::remove_reference_t; if (it == end) IGUANA_UNLIKELY { throw std::runtime_error("Unexexpected eof"); } @@ -469,6 +467,8 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { using value_type = typename T::value_type; value_type t; if constexpr (string_v || string_view_v) { + if (it < end && *it == '"') + IGUANA_LIKELY { ++it; } from_json_impl(t, it, end); } else { diff --git a/test/test_json_files.cpp b/test/test_json_files.cpp index 035c5b48..2d609cb9 100644 --- a/test/test_json_files.cpp +++ b/test/test_json_files.cpp @@ -314,6 +314,21 @@ TEST_CASE("test instruments.json") { } } +struct test_optstr_reader_null { + std::optional name; +}; +YLT_REFL(test_optstr_reader_null, name); +TEST_CASE("test_optstr_reader") { + test_optstr_reader_null v; + v.name = "name"; // optional begin with 'n' + std::string json; + iguana::to_json(v, json); + + test_optstr_reader_null v1; + iguana::from_json(v1, json); + CHECK(v.name == v1.name); +} + // doctest comments // 'function' : must be 'attribute' - see issue #182 DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007) int main(int argc, char **argv) {