Closed riidefi closed 11 months ago
Thank you for your input.
I was actually thinking about this problem just a couple of days ago. I think there is a simple fix to this. I'll implement it tonight and will let you know.
Here, this should fix your issue:
https://github.com/getml/reflect-cpp/commit/b67a2fababc97847fb3d49a3e2777b4b16b62b8a
I couldn't reproduce the example you have provided, because there were some classes you didn't define, but I have written my own test for this:
struct Person {
rfl::Field<"firstName", std::string> first_name;
rfl::Field<"lastName", std::string> last_name = "Simpson";
rfl::Field<"children", std::vector<Person>> children =
rfl::default_value;
};
const auto bart = Person{.first_name = "Bart"};
write_and_read(
bart,
"{\"firstName\":\"Bart\",\"lastName\":\"Simpson\",\"children\":[]}");
The test proves that setting default values in the way you proposed works and we get the expected outcome.
I will also add documentation for this.
Thanks again for your input.
Thanks for the swift reply. That seems to have resolved one issue, although I am now running into another. I'll open another issue.
In this case, this was the code
Similarly having name be default set causes issues too:
s
is written as"{}"
since it is assumed to have zero fields given it is itself default-constructible.Compiler: Clang 16.0.5 Target: x64 Windows Host: Windows 11 x64