Repository navigation
Read metadata comments and trailing commas, and let a generator set its JSON options [minor] - #69
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
…ts JSON options [minor] Hand-maintained metadata with a // or /* */ comment or a trailing comma failed with MetadataParseFailed, and a consumer had no way to change the fixed JsonSerializerOptions MetadataFile used. The shared default now skips comments and allows trailing commas, and is exposed read-only as MetadataFile.DefaultSerializerOptions. Deserialize<T> gains an overload that takes options, and GeneratorBase<T> passes a virtual MetadataSerializerOptions through it. Fixes #49 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3R5YfaNjqL9oXpRg6
|
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 #49
Hand-maintained metadata files that contained a
//or/* */comment or a trailing comma failed withMetadataParseFailed. Consumers also had no way to change the fixed, privateJsonSerializerOptionsthatMetadataFileused. This PR implements both options from the issue.Changes
ReadCommentHandling = SkipandAllowTrailingCommas = true. This only accepts input that was rejected before. The options are exposed asMetadataFile.DefaultSerializerOptionsand made read-only (MakeReadOnly), so a consumer can copy them but cannot change the shared instance.MetadataFile.Deserialize<T>(context, parseFailed, JsonSerializerOptions).GeneratorBase<T>gets aprotected virtual JsonSerializerOptions MetadataSerializerOptions, which defaults to the shared instance and is passed through to that overload. The XML docs and README tell consumers to return a cachedstatic readonlyinstance (CA1869).[minor]because this adds public API.Tests
AHandWrittenMetadataFileWithCommentsAndTrailingCommasParses: a fixture with//and/* */comments and trailing commas in both objects and arrays generates with no diagnostic.AGeneratorCanOverrideTheMetadataSerializerOptions: a fixture generator addsJsonStringEnumConverterand reads an enum from its string name.TheDefaultMetadataSerializerOptionsAreReadOnly.GeneratorBase<T>ignoring the override. They pass with it. The full suite passes (83 tests), including the existing parse-failure tests, anddotnet build -warnaserroris clean.Generated by Claude Code