Skip to content

Type check the actual values during deserialization in polymorphic scenarios - #41323

Closed
devsko wants to merge 15 commits into
dotnet:masterfrom
devsko:fix-41146
Closed

Type check the actual values during deserialization in polymorphic scenarios#41323
devsko wants to merge 15 commits into
dotnet:masterfrom
devsko:fix-41146

Conversation

@devsko

Copy link
Copy Markdown
Contributor

This is a follow up from #40931
Fixes#41146.

This PR adds type checks to the property/field setter when a JsonConverter could potentially have returned an incompatible typed value.
There should be no impact on deserialization performance in the majority of cases where these checks are unnecessary.
The behavior should not depend on the used MemberAccessor implementation. To accomplish this, a JsonException is thrown when a direct assignment would throw an InvalidCastException or null is assigned to a non-nullable value type (in this case calling the setter by reflection, silently assigns default and doesn't throw at all).

@devskodevsko changed the title [WIP] Type check the actual values during deserialization in polymorphic scenariosType check the actual values during deserialization in polymorphic scenariosAug 25, 2020
@devsko

Copy link
Copy Markdown
ContributorAuthor

@layomia PTAL
Once #40914 is merged I will rebase this PR

@devsko

Copy link
Copy Markdown
ContributorAuthor

Added to #40914 again. Close

@devskodevsko closed this Aug 25, 2020
@devsko
devsko deleted the fix-41146 branch August 26, 2020 06:09
@ghostghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add runtime type checks when setting properties during json deserialization

2 participants

@devsko@Dotnet-GitSync-Bot