Closed tim-lyon closed 4 days ago
Thanks for the contribution. You are right, of course.
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}
For the example to compile, the
ProcessorsType
needs to be passed though to the custom perser's template params?