Skip to content

Conversation

@devsko
Copy link
Contributor

@devsko devsko commented Aug 25, 2020

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).

@devsko devsko changed the title [WIP] Type check the actual values during deserialization in polymorphic scenarios Type check the actual values during deserialization in polymorphic scenarios Aug 25, 2020
@devsko
Copy link
Contributor Author

devsko commented Aug 25, 2020

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

@devsko
Copy link
Contributor Author

devsko commented Aug 25, 2020

Added to #40914 again. Close

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

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