Uh oh!
There was an error while loading. Please reload this page.
Add GetTypeInfo<T>() and TryGetTypeInfo<T>() to JsonSerializerOptions - #123940
Conversation
…lizerOptions Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
stephentoub
left a comment
There was a problem hiding this comment.
@copilot are there any places throughout the repo where non-generic {Try}GetTypeInfo methods are being used that the new generic ones should be used instead? Please search for and replace such uses.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Tagging subscribers to this area: @dotnet/area-system-text-json |
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Updated 15 usages across 6 test files to use the new generic methods in 64eab66:
No production code usages were found (only test code was using the cast pattern). |
stephentoub
commented
Feb 3, 2026
@copilot, what about places like: etc.? |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Updated the production code in b40934d:
|
Uh oh!
There was an error while loading. Please reload this page.
…eedback Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
agocke
commented
Feb 3, 2026
@stephentoub thanks! I planned to do this myself, but hadn’t gotten around to it yet |
Co-authored-by: stephentoub <515774+stephentoub@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
…dotnet#123940) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: stephentoub <515774+stephentoub@users.noreply.github.com>
…dotnet#123940) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: stephentoub <515774+stephentoub@users.noreply.github.com>
Description
Implements the approved API from API review to add generic overloads of
GetTypeInfothat returnJsonTypeInfo<T>directly, eliminating the need for manual downcasting.Changes
GetTypeInfo<T>()andTryGetTypeInfo<T>()instance methods that delegate to the non-generic versions(JsonTypeInfo<T>)options.GetTypeInfo(typeof(T))with the new genericoptions.GetTypeInfo<T>():JsonNode.cs-JsonNode.ToNode<T>()JsonValue.cs-JsonValue.Create<T>()PolymorphicTests.csCustomConverterTests.Object.csOptionsTests.csJsonValueTests.csJsonSerializerContextTests.csUsage
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.