Skip to content

Ignore unmatched keys in the YAML serialization provider [patch] - #110

Merged
matt-edmondson merged 2 commits into
mainfrom
claude/yaml-ignore-unmatched-88
Oct 14, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
claude/yaml-ignore-unmatched-88

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #88

What changed

  • YamlSerializationProvider builds its deserializer with .IgnoreUnmatchedProperties(). Before, any key the target type lacked threw a YamlException inside YamlDotNet, Deserialize<T> swallowed it, and the caller got default. Removing or renaming a property made every earlier YAML record read back as missing. The JSON providers accept the same document.
  • New contract test, RoundTripTests.Serialization_Ignores_Members_The_Target_Type_Lacks. It runs over every serialization provider registered by AddCommon() (Json, NewtonsoftJson, Yaml, Toml): it serializes a record with an extra Legacy member, deserializes it into the narrower type, and checks that the known members come through.

Verification

  • With the fix reverted, the new test fails for YamlSerializationProvider only and passes for the other three, so TOML already behaves the same way (the issue asked about that).
  • With the fix in place, the full Essentials.Tests suite passes on net10.0 (1020/1020).

🤖 Generated with Claude Code

https://claude.ai/code/session_013bVvLeJqTVbPQBchoFvNKE


Generated by Claude Code

The YAML deserializer was built without IgnoreUnmatchedProperties, so a
document with any key the target type lacks threw inside YamlDotNet and
Deserialize returned default. Removing or renaming a property therefore
made every earlier YAML record read back as missing, while the JSON
providers accepted the same document. The deserializer now ignores
unmatched keys, and a contract test over every registered serialization
provider asserts that a wider record loads into the narrower type.

Fixes #88

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013bVvLeJqTVbPQBchoFvNKE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013bVvLeJqTVbPQBchoFvNKE
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit e19211c into main Oct 14, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the claude/yaml-ignore-unmatched-88 branch October 14, 2026 01:19
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.

YAML provider returns null for a document containing any property the target type lacks, so removing a property orphans every saved YAML record

2 participants