-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Labels
kind: bugsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
Milestone
Description
Description
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT should not throw an exception when the json instance is empty and should use the default values of the member fields
Reproduction steps
run the Minimal code example and get the exception
Expected vs. actual results
don't expect to get exception with an empty JSON
expect that foo member fields are filled with they default values
Minimal code example
class Foo {
public:
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Foo, a, b)
Foo() = default;
int a{10};
std::string b{"bar"};
void log() {
std::cout << "a: " << a << std::endl;
std::cout << "b: " << b << std::endl;
}
};
// with an empty json, an exception is thrown instead of getting default values
static void JsonTest_empty_json() {
nlohmann::json json{};
auto foo = Foo(json);
foo.log();
}
int main(int argc, char **argv) {
JsonTest_empty_json();
return 0;
}
Error messages
No response
Compiler and operating system
clang++ / C++17 / Windows OS
Library version
ref: v3.11.2 - commit: 7d2f9ad500cf062394040f44d006791ff7cfc1c1
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.
Metadata
Metadata
Assignees
Labels
kind: bugsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation