Repository navigation
Add opt-in rfl::NoDuplicateKeys processor for JSON and YAML - #128
Open
clockblocker wants to merge 1 commit into
Open
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in
rfl::NoDuplicateKeysprocessor (matchingrfl::NoExtraFieldsandrfl::EnumNamesOnly) that rejects repeated object/mapping keys during JSON and YAML deserialization while leaving default behavior 100% backwards-compatible and zero-overhead when unused.include/rfl/NoDuplicateKeys.hpp&include/rfl/internal/no_duplicate_keys_v.hpp: Opt-in marker processor +reader_supports_no_duplicate_keys_v<R>trait. Passingrfl::NoDuplicateKeysto a reader without duplicate-key support fails at compile time (static_assert).include/rfl/json/Reader.hpp: Wiressupports_no_duplicate_keys = truewith zero-copystd::unordered_set<std::string_view>over theyyjsonbuffer (if constexprzero overhead when unused). Works across structs (ViewReader/ViewReaderWithDefault),std::map/rfl::Object(MapReader),rfl::Generic(nested arbitrarily deep),rfl::FieldVariant, andrfl::TaggedUnion(including duplicate discriminators).include/rfl/yaml/Reader.hpp: Wiressupports_no_duplicate_keys = trueinread_object, reporting each repeated key viaadd_error()(aggregated alongside other field errors and honoringrfl::FailFast).docs/content/processors.mdand addedtests/json/test_no_duplicate_keys.cppandtests/yaml/test_no_duplicate_keys.cpp.Motivation
yaml-cppinsrc/config/loader/YamlDuplicateKeys.h(L13–19) specifically becauseyaml-cpppreserves repeated keys andreflect-cppsilently drops or overwrites them:Verification
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror): passed; 0 relative-include errors.static_assertverified for unsupportedrfl::generic::Reader.tests/json/test_no_duplicate_keys.cpp+tests/yaml/test_no_duplicate_keys.cppunder-fsanitize=undefined -fno-sanitize-recover=all: 8/8 passed.