-
We are using the latest develop code of the The incoming JSON we are parsing may not include the fields which are optional. Right now the code generated by Is it possible to skip such field and not throw? Compiler Explorer sample: https://godbolt.org/z/3P58EWhqd namespace ns {
struct info {
std::optional<int> start;
std::optional<int> end;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(info, start, end)
};
}
// this will throw `out_of_range.403` because the `end` field is not present in the JSON data
json j = R"( { "start": null } )"_json;
ns::info i = j.template get<ns::info>();
I have found these similar question: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is a difference between (1) the field is |
Beta Was this translation helpful? Give feedback.
It is a difference between (1) the field is
null
and (2) the field is not provided in the JSON object at all. You probably want to tryNLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT
.