Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fallback to reflection converter resolution #72228

Merged

Conversation

eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis commented Jul 14, 2022

Contributes to #71714 by removing fallback to the reflection converters for any resolver other than the default reflection-based resolver. More specifically this change:

  • Makes contract resolvers the only source of truth when it comes to determining converters for types or properties.
  • The reflection-based converter factories are only consulted by DefaultContractResolver (and JsonSerializerOptions.GetConverter whenever a resolver is left unspecified for backward compatibility purposes).
  • Makes converter resolution for JsonPropertyInfo explicitly lazy unless the JsonTypeInfo for the declared type has already been cached.
  • Changes the behavior of JsonSerializerOptions.GetConverter for options instances tied to JsonSerializerContext: the method will throw NotSupportedException for any type not explicitly supported by the context and will not query the reflection-based converter factories. This change is inline with the proposal in Remove implicit fallback to reflection-based serialization in System.Text.Json sourcegen #71714.
  • Adds test coverage for recursive types containing Nullable<T> and F# optionals: types whose converters perform eager resolution for the converters of their element types.

Fix #71714.

@ghost
Copy link

ghost commented Jul 14, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Contributes to #71714 by removing fallback to the reflection converters for any resolver other than the default reflection-based resolver. More specifically this change:

  • Makes contract resolvers the only source of truth when it comes to determining converters for types or properties.
  • The reflection-based converter factories are only consulted by DefaultContractResolver (and JsonSerializerOptions.GetConverter whenever a resolver is left unspecified for backward compatibility purposes).
  • Makes converter resolution for JsonPropertyInfo explicitly lazy unless the JsonTypeInfo for the declared type has already been cached.
  • Changes the behavior of JsonSerializerOptions.GetConverter for options instances tied to JsonSerializerContext: the method will throw NotSupportedException for any type not explicitly supported by the context and will not query the reflection-based converter factories. This change is inline with the proposal in Remove implicit fallback to reflection-based serialization in System.Text.Json sourcegen #71714.
  • Adds test coverage for recursive types containing Nullable<T> and F# optionals: types whose converters perform eager resolution for the converters of their element types.
Author: eiriktsarpalis
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some comments

@eiriktsarpalis eiriktsarpalis merged commit 50fa756 into dotnet:main Jul 16, 2022
@eiriktsarpalis eiriktsarpalis deleted the remove-reflection-converter-fallback branch July 16, 2022 10:10
@ghost ghost locked as resolved and limited conversation to collaborators Aug 15, 2022
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.

Remove implicit fallback to reflection-based serialization in System.Text.Json sourcegen
2 participants