Fix exception thrown during deserialization for generic base type - #184
Merged
Conversation
- Guard MakeGenericType against arity mismatch (clean JsonSerializationException instead of ArgumentException) - Restrict generic CanConvert matching to the base class hierarchy only; interface matching is used only against registered subtypes, so unrelated types that merely implement the generic base interface are no longer claimed - Add edge-case tests proving the previous issues (arity, unrelated interface implementors)
Type.GetGenericArguments is not available on netstandard1.3; use a GetGenericTypeParameterCount helper (TypeInfo.GenericTypeParameters there, GetGenericArguments elsewhere).
Rename InheritsOrImplementsGeneric to IsClosedGenericFormOf with an includeInterfaces opt-in parameter and a doc comment explaining why interface matching is only enabled against registered subtypes. Add tests for: multi-level generic hierarchies, explicit closed-form registration precedence over the open generic, and a generic fallback subtype being closed during deserialization.
The previous model mixed integers as both the generic type argument and the discriminator value (Nested1<int> with Kind => "1"), which was confusing. Use ShapeBase/Square/Circle with 'square'/'circle' discriminators and assert the resolved type.
…case Registering an interface as a subtype cannot work end-to-end (deserialization would resolve to a non-instantiable interface), and the interface-base scenario works through the definition match against registered class subtypes. Removing interface matching simplifies IsClosedGenericFormOf, drops GetImplementedInterfaces and eliminates the unrelated-interface-implementor risk.
…eline Add the #177 fix to the [Unreleased] section so reviewers see the intended changelog entry, and add a pull request template requiring a changelog entry, tests and docs for every contribution (humans and agents alike).
The two packages have independent release timelines, so mixing their entries under one Unreleased section was unmanageable.
… sections JsonSubTypes.Text.Json 1.0.0-rc.1 and rc.2 are published, so their entries move out of [Unreleased] into dedicated released sections; [Unreleased] now only tracks the pending JsonSubTypes change (#177).
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.
No description provided.