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

[Bug] rfl::DefaultIfMissing omits vector entries #367

Closed
fengelniederhammer opened this issue Feb 27, 2025 · 3 comments
Closed

[Bug] rfl::DefaultIfMissing omits vector entries #367

fengelniederhammer opened this issue Feb 27, 2025 · 3 comments

Comments

@fengelniederhammer
Copy link
Contributor

I found this library - it looks very promising and pretty much exactly like what I've been looking for!

I've been playing around with it a little to see whether it fits a use case that I'm investigating. I found that when using rfl::DefaultIfMissing, rfl::xml::read would omit entries of a vector. I was able to reproduce the issue in a minimal example:

#include <string>
#include <fstream>
#include <iostream>

#include <pugixml.hpp>
#include <rfl.hpp>
#include <rfl/xml.hpp>

namespace rfl_test {
	struct Person {
		std::string name;
		std::vector<std::string> children;
	};

	inline void reflectMain() {
		std::cout << "reflectMain: \n\n";

		const auto xml = R"(
			<Person>
				<name>Peter</name>
				<children>first child</children>
				<children>second child</children>
			</Person>
		)";

		std::cout << "without DefaultIfMissing: \n\n";

		{
			const rfl::Result<Person> result = rfl::xml::read<Person>(xml);
			auto p = result.value();

			std::cout << "Name: " << p.name << "\n";
			for (const auto& child : p.children) {
				std::cout << "Child: " << child << "\n";
			}
		}

		std::cout << "with DefaultIfMissing: \n\n";

		{
			const auto result = rfl::xml::read<Person, rfl::DefaultIfMissing>(xml);
			auto p = result.value();

			std::cout << "Name: " << p.name << "\n";
			for (const auto& child : p.children) {
				std::cout << "Child: " << child << "\n";
			}
		}
	}
}

which yields

reflectMain:

without DefaultIfMissing:

Name: Peter
Child: first child
Child: second child


with DefaultIfMissing:

Name: Peter
Child: second child

As you can see, Child: first child is missing.

(In case it matters: I was using Windows 11 with Visual Studio 2022)

@liuzicheng1987
Copy link
Contributor

Thanks for reporting. This one is interesting.

@liuzicheng1987
Copy link
Contributor

@fengelniederhammer , issue resolved thanks for reporting

@fengelniederhammer
Copy link
Contributor Author

Great, thanks for fast response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants