Skip to content

Commit

Permalink
fix json
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Sep 4, 2023
1 parent 7cf69d1 commit 38fbd9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 0 additions & 2 deletions include/ylt/thirdparty/iguana/json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,6 @@ IGUANA_INLINE void parse_item(U &value, It &&it, It &&end) {
template <typename U, typename It, std::enable_if_t<smart_ptr_v<U>, int>>
IGUANA_INLINE void parse_item(U &value, It &&it, It &&end) {
skip_ws(it, end);
if (it < end && *it == '"')
IGUANA_LIKELY { ++it; }
if (it == end)
IGUANA_UNLIKELY { throw std::runtime_error("Unexexpected eof"); }
if (*it == 'n') {
Expand Down
20 changes: 20 additions & 0 deletions src/struct_json/examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ void test_inner_object() {
assert(obj1.get_name() == "tom");
}

struct person1 {
std::shared_ptr<std::string> name;
std::unique_ptr<int64_t> age;
};
REFLECTION(person1, name, age);

void use_smart_pointer() {
person1 p{std::make_shared<std::string>("tom"),
std::make_unique<int64_t>(42)};
std::string str;
iguana::to_json(p, str);

person1 p1;
iguana::from_json(p1, str); // here throw exception

assert(*p1.name == "tom");
assert(*p1.age == 42);
}

int main() {
person p{"tom", 20};
std::string str;
Expand All @@ -59,4 +78,5 @@ int main() {
assert(val.at<int>("age") == 20);

test_inner_object();
use_smart_pointer();
}

0 comments on commit 38fbd9c

Please sign in to comment.