Repository navigation
Round-trip Chord, Phrase, Command and Profile through System.Text.Json [patch] - #178
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
…n [patch] Chord and Phrase had two public constructors and no [JsonConstructor], so deserializing their own output threw NotSupportedException. Each now has a private [JsonConstructor] taking its property's own type, which is what the serializer binds against. Command's semantic strings serialized as char arrays. A SemanticStringJsonConverter writes them as plain strings and reads them back through Create, and the semantic-string constructor is marked [JsonConstructor]. Profile.Chords is get-only, so a deserialized profile silently came back with no bindings. A private [JsonConstructor] takes the chords and binds them through SetChord. Populate handling was not an option: System.Text.Json does not support it on a type with a parameterized constructor. Fixes #141 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T4yQx7YuowTGorXJRkhe8x
|
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 #141
What changed
[JsonConstructor]takingIReadOnlyList<Note>/IReadOnlyList<Chord>. System.Text.Json binds constructor parameters by name and exact type, so marking the existingIEnumerable<T>constructors (as the issue suggested) fails withInvalidOperationException. The new constructors just forward to the public ones, so deduplication and validation still apply.SemanticStringJsonConverter<T>is applied toId,Name,DescriptionandCategory, so they serialize as JSON strings and not as char arrays. The semantic-string constructor is marked[JsonConstructor].[JsonObjectCreationHandling(Populate)]isn't supported on a type with a parameterized constructor, so a private[JsonConstructor]takes achordsdictionary and binds each entry throughSetChord. This keeps the existing trimming and null checks.The private constructors carry an
IDE0051suppression, because only the serializer calls them.Tests
ModelJsonSerializationTests(6 tests) sits next to the existingNoteJsonSerializationTests. It covers round-trips forChord,Phrase,Command(with and without description/category) andProfile(including its bound chords), and checks that theCommandfields serialize as JSON strings.Keybinding.slnbuilds clean on net8.0, net9.0 and net10.0.🤖 Generated with Claude Code
https://claude.ai/code/session_01T4yQx7YuowTGorXJRkhe8x
Generated by Claude Code