Repository navigation
feat: register JSON contexts and accept JsonTypeInfo parameters - #2333
Merged
Merged
Conversation
- ForGenerated, AddRefitGeneratedClient and the keyed variants take a JsonSerializerContext. Reflection-based JSON is off unless allowReflectionFallback is true. - Settings you pass keep their naming, converters, resolvers and polymorphism registrations. With none, the context's own options apply. - RefitSettings.ForJsonContext, RefitSettings.UseJsonContext, SystemTextJsonContentSerializer.ForContext and WithContext serve the reflection APIs too. - A generated method can take JsonTypeInfo<T> parameters for its JSON body and its reply. RF014 reports a parameter that cannot be used, and the reflection request builder refuses one. - IJsonTypeInfoContentSerializer adds metadata overloads to SystemTextJsonContentSerializer. - Runnable order examples show each way to set up JSON, and the Native AOT smoke test creates its client from a context.
2 of 3 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2333 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 206 211 +5
Lines 10805 11083 +278
Branches 2106 2154 +48
==========================================
+ Hits 10805 11083 +278 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
ChrisPulman
approved these changes
Sep 21, 2026
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Generated Refit clients take a source-generated JSON context, and methods can take
JsonTypeInfo<T>parameters, so a first Native AOT client needs no hand-built JSON options.RestService.ForGenerated<T>,AddRefitGeneratedClient<T>andAddKeyedRefitGeneratedClient<T>take aJsonSerializerContext, with settings andallowReflectionFallbackvariants.NotSupportedException, andallowReflectionFallback: trueopts in to reflection.RefitSettings.ForJsonContext,RefitSettings.UseJsonContext,SystemTextJsonContentSerializer.ForContextandWithContextwork withRestService.For<T>andAddRefitClient<T>.JsonTypeInfo<T>parameters. The generator matches each one byTto the JSON body or the reply, forTask<T>,ApiResponse<T>,IAsyncEnumerable<T>,IObservable<T>and paged replies.RF014reports a parameter that cannot be used. The reflection request builder throws for such a parameter instead of sending it as a body or query value.IJsonTypeInfoContentSerializeradds metadata overloads.SystemTextJsonContentSerializerimplements it for bodies, replies, buffered text and framed streams.Why
Getting a first Native AOT client right meant building
JsonSerializerOptions, aTypeInfoResolver, a serializer and settings by hand. A context declared without the web defaults also reads camelCase replies as empty objects and reports no error. No issue tracks this.Breaking changes
None. Every addition is source compatible. The two
RestService.ForGenerated<T>(..., RefitSettings)overloads carryOverloadResolutionPriority, soForGenerated<T>(client, new())binds to the settings overload, andSystemTextJsonContentSerializerimplements one more interface.How this was verified
Tests cover the runtime, the generator diagnostics, emission and snapshots, and generated clients run against a stub handler. The Native AOT smoke test and the documentation client were published with
dotnet publish -r linux-x64and run.Notes for the reviewer
Parser.Request.Parameters.csandGeneratedRequestRunner.JsonTypeInfo.csfor the parameter support, andSystemTextJsonContentSerializer.JsonContext.csfor how options and contexts compose. That file is the subtle part.src/examples/Documentation/JsonContexts, the snapshots and the public API baselines are mechanical to skim.[JsonSerializable]entries, because one JSON source generator cannot read another's output.CLAUDE.mdcarries the design notes. The website pages are in a companion pull request in reactiveui/website.Checklist