Serialize Note as {"Key":"CTRL"} so it round-trips through System.Text.Json - #137
Merged
Merged
Conversation
…t.Json [patch]
NoteName is a SemanticString, which System.Text.Json treats as a collection
of chars, so Note serialized as {"Key":["C","T","R","L"]} and could not be
read back. A JsonConverter on Note now writes the key as a string and reads
it through the normalizing Note(string) constructor, so lowercase and alias
input deserializes to the canonical note.
Fixes #122
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X65VbCUfvG15D4o8afrvpk
…AreSequenceEqual Addresses SonarCloud S3776 (cognitive complexity 16 > 15) and MSTEST0068. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X65VbCUfvG15D4o8afrvpk
|
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.



Fixes #122
What was wrong
NoteNameis a SemanticString, so System.Text.Json treated it as a char collection:new Note("Ctrl")serialized to{"Key":["C","T","R","L"]}, and neither that nor{"Key":"CTRL"}could be deserialized.Noteadvertised direct serialization through[JsonConstructor]anyway.Change
NoteJsonConverter, attached with[JsonConverter]onNote.{"Key":"CTRL"}, and applies the options'PropertyNamingPolicyto the property name.Keyproperty (matched case-insensitively, other properties skipped) through the normalizingNote(string)constructor, soctrlandControlboth come back asCTRL.JsonException.ChordholdsNotes, aChord's notes now serialize as strings too.ChordandPhrasestill cannot be deserialized directly, since neither has a[JsonConstructor]. The issue doesn't ask for that, so it isn't in this PR.Tests
NoteJsonSerializationTestshas 12 tests: serialization, naming policy, round-trip, lowercase and alias input, camelCase property name, unknown properties, null, notes inside a list, and the error cases. With the attribute removed, 9 of them fail. Full suite: 114/114 pass on net10.0.🤖 Generated with Claude Code
https://claude.ai/code/session_01X65VbCUfvG15D4o8afrvpk
Generated by Claude Code