diff --git a/include/yaml_cpp_struct.hpp b/include/yaml_cpp_struct.hpp index e184024..58a96ed 100644 --- a/include/yaml_cpp_struct.hpp +++ b/include/yaml_cpp_struct.hpp @@ -306,7 +306,8 @@ struct convert> { using ToType = std::remove_reference_t>; \ if constexpr (yaml_cpp_struct::is_optional()) { \ try { \ - value = yaml_cpp_struct::node_as(node[name]); \ + if (node[name]) \ + value = yaml_cpp_struct::node_as(node[name]); \ } catch (const std::runtime_error&) { \ } \ } \ @@ -339,7 +340,8 @@ struct convert> { visit_struct::for_each(rhs, [&](const char* name, auto& value) { \ using ToType = std::remove_reference_t>; \ try { \ - value = yaml_cpp_struct::node_as(node[name]); \ + if (node[name]) \ + value = yaml_cpp_struct::node_as(node[name]); \ } catch (const std::runtime_error&) { \ } \ }); \