Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Add opt-in rfl::NoDuplicateKeys processor for JSON and YAML - #128

Open
clockblocker wants to merge 1 commit into
mainfrom
feat-no-duplicate-keys
Open

clockblocker wants to merge 1 commit into
mainfrom
feat-no-duplicate-keys

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in rfl::NoDuplicateKeys processor (matching rfl::NoExtraFields and rfl::EnumNamesOnly) that rejects repeated object/mapping keys during JSON and YAML deserialization. Default behavior is unchanged with zero overhead when unused.

Example

struct Config { int port; };

// Rejected under NoDuplicateKeys instead of silently taking one value:
auto res = rfl::json::read<Config, rfl::NoDuplicateKeys>(R"({"port": 80, "port": 443})");

Key details

  • Guarded by if constexpr (zero instructions when unused); passing rfl::NoDuplicateKeys to a reader without duplicate-key support fails at compile time via static_assert.
  • JSON: tracks seen keys with zero-copy std::unordered_set<std::string_view> over the yyjson buffer across structs, maps/rfl::Object, rfl::Generic (arbitrarily nested), FieldVariant, and TaggedUnion (including duplicate discriminators).
  • YAML: reports each repeated mapping key via add_error() (aggregated with other field errors and honoring rfl::FailFast), replacing hand-rolled yaml-cpp pre-passes (e.g. openmoq/moqx).
  • Documented in docs/content/processors.md.

AI-authored.

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