getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]
https://getml.github.io/reflect-cpp/
MIT License
783 stars 63 forks source link

Fix typo in custom parser docs #137

Closed tim-lyon closed 4 days ago

tim-lyon commented 4 days ago

For the example to compile, the ProcessorsType needs to be passed though to the custom perser's template params?

liuzicheng1987 commented 4 days ago

Thanks for the contribution. You are right, of course.

tim-lyon commented 3 days ago

Thanks for merging @liuzicheng1987!

I also suspect the documentation on anonymous fields might be out of date, as it appears the default behaviour now picks up the field names? Is it worth opening an issue for? My follow-on question is, with the new behaviour, is there a way to force a field to become anonymous? Thanks, loving the library so far!

[edit] to clarify my question, Lets say I have a struct Age that wraps an integer - I'd like to parse this struct as a primitive type (integer) for serialisation purposes:

struct Age { int value; };
struct Person { std::string name; Age age; };
Person homer { .name = "Homer", .age = Age(45) };
std::string json_string = rfl::json::write(homer);
// default result: {"name":"Homer","age":{"value":45}}
// required result: {"name":"Homer","age":45}

[edit] OK I found rfl::Flatten which can achieve the example requirement with minor edit, nice!

struct Age { int age; };
struct Person { std::string name; rfl::Flatten<Age> age; };
Person homer { .name = "Homer", .age = Age(45) };
std::string json_string = rfl::json::write(homer);
// result: {"name":"Homer","age":45}