Skip to content

Fix exception thrown during deserialization for generic base type - #184

Merged
manuc66 merged 12 commits into
masterfrom
feature/deserialization-generic-base-type
Aug 11, 2026
Merged

Fix exception thrown during deserialization for generic base type#184
manuc66 merged 12 commits into
masterfrom
feature/deserialization-generic-base-type

Conversation

@manuc66

@manuc66 manuc66 commented Nov 15, 2025

Copy link
Copy Markdown
Owner

No description provided.

manuc66 and others added 12 commits November 15, 2025 23:31
- 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).
@manuc66
manuc66 merged commit 2a8e084 into master Aug 11, 2026
5 checks passed
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.

2 participants