Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[struct_json][fix]fix json #440

Merged
merged 3 commits into from
Sep 4, 2023
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
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);

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();
}
Loading