Skip to content

Add opt-in rfl::DefaultIfNull processor (#796) - #79

Open
clockblocker wants to merge 5 commits into
mainfrom
default-if-null
Open

clockblocker wants to merge 5 commits into
mainfrom
default-if-null

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in, format-general rfl::DefaultIfNull processor that treats null/empty input values (_r.is_empty(_var)) as default-constructed values across YAML, JSON, Generic, and other readers, while leaving default behavior without DefaultIfNull completely unchanged.

Addresses munich-data-engineering#796

Details

  • Added include/rfl/DefaultIfNull.hpp and include/rfl/internal/default_if_null_v.hpp (wired into include/rfl.hpp).
  • Handles all 6 YAML/JSON cases from #796: empty document, all-commented YAML document, null sequence (tags:), null map (env:), null nested struct (logging:) preserving DMIs, and null map/container element (modules:\n network:).
  • Preserves in-class member initializers (DMIs) on default-constructible struct fields (e.g. int port = 8080; stays 8080 on port: null), keeps missing required fields failing unless rfl::DefaultIfMissing is also passed, and keeps nullable types (std::optional, std::unique_ptr, std::shared_ptr, raw pointers, rfl::Generic) decoding explicit null as empty even when they have non-null DMIs.
  • Non-default-constructible structs/fields compile cleanly and fall through to standard error reporting.
  • Added comprehensive YAML and JSON tests (tests/yaml/test_default_if_null.cpp, tests/json/test_default_if_null.cpp) and documented in docs/content/processors.md.

Verification

  • ctest -R "(yaml\.|default|null|optional)": 134/134 PASSED.
  • Full ctest suite (json, yaml, generic, cli, env, json_c_arrays_and_inheritance) under -Wall -Werror: 666/666 PASSED.

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

Successfully merging this pull request may close these issues.

1 participant