{"record":{"id":"dc6a42308c9ea854","repo":"reactiveui/refit","slug":"systemtextjsonqueryconverter-requires-refitsetting","errorCode":null,"errorMessage":"SystemTextJsonQueryConverter requires RefitSettings.ContentSerializer to be a SystemTextJsonContentSerializer.","messagePattern":"SystemTextJsonQueryConverter requires RefitSettings\\.ContentSerializer to be a SystemTextJsonContentSerializer\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Refit/SystemTextJsonQueryConverter.cs","lineNumber":35,"sourceCode":"/// The value's runtime type is walked, so a polymorphic value contributes its actual properties. When the configured\n/// serializer uses a source-generated <c>TypeInfoResolver</c> the walk is reflection- and AOT-free; otherwise it falls\n/// back to System.Text.Json's reflection resolver. Nested objects are flattened under a dotted key; collections use the\n/// configured <see cref=\"RefitSettings.CollectionFormat\"/>.\n/// </remarks>\n[System.Diagnostics.DebuggerDisplay(\"{ToString(),nq}\")]\npublic sealed class SystemTextJsonQueryConverter<T> : IQueryConverter<T>\n{\n    /// <inheritdoc/>\n    public void Flatten(T value, string keyPrefix, ref GeneratedQueryStringBuilder builder, RefitSettings settings)\n    {\n        if (value is null)\n        {\n            return;\n        }\n\n        if (settings.ContentSerializer is not SystemTextJsonContentSerializer serializer)\n        {\n            throw new NotSupportedException(\n                $\"SystemTextJsonQueryConverter requires {nameof(RefitSettings)}.{nameof(RefitSettings.ContentSerializer)} to be a {nameof(SystemTextJsonContentSerializer)}.\");\n        }\n\n        SystemTextJsonQueryFlattener.FlattenObject(value, keyPrefix, ref builder, settings, serializer.SerializerOptions, 0);\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":42,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit/SystemTextJsonQueryConverter.cs#L17-L42","documentation":"SystemTextJsonQueryConverter<T>.Flatten throws NotSupportedException when RefitSettings.ContentSerializer is not a SystemTextJsonContentSerializer. The converter reuses the serializer's JsonSerializerOptions to flatten the value, so a different serializer implementation cannot supply those options.","triggerScenarios":"Registering SystemTextJsonQueryConverter<T> as the query converter for a type while RefitSettings.ContentSerializer is a non-System.Text.Json serializer (e.g. Newtonsoft.Json or a custom IHttpContentSerializer). The mismatch is detected on the first call to Flatten for a non-null value.","commonSituations":"Mixing a Newtonsoft-based content serializer with the System.Text.Json query converter; registering the query converter globally without aligning the content serializer; upgrading Refit and inheriting the converter while the app still uses a legacy serializer.","solutions":["Set RefitSettings.ContentSerializer to a SystemTextJsonContentSerializer so the options are available","If you must use a different content serializer, write a custom IQueryConverter that does not depend on System.Text.Json options","Align both the content serializer and the query converter to the same JSON stack","Register the query converter only for interfaces whose settings use SystemTextJsonContentSerializer"],"exampleFix":"// before\nvar settings = new RefitSettings(new NewtonsoftJsonContentSerializer());\nsettings.QueryConverter = new SystemTextJsonQueryConverter<MyFilter>();\nawait api.SearchAsync(filter); // throws - serializer mismatch\n\n// after\nvar jsonOpts = new JsonSerializerOptions();\nvar settings = new RefitSettings(new SystemTextJsonContentSerializer(jsonOpts));\nsettings.QueryConverter = new SystemTextJsonQueryConverter<MyFilter>();","handlingStrategy":"type-guard","validationCode":"if (settings.ContentSerializer is not SystemTextJsonContentSerializer)\n    throw new NotSupportedException(\n        \"SystemTextJsonQueryConverter requires a SystemTextJsonContentSerializer.\");\nsettings.QueryConverter = new SystemTextJsonQueryConverter<MyFilter>();","typeGuard":"static bool IsSystemTextJson(RefitSettings s) =>\n    s.ContentSerializer is SystemTextJsonContentSerializer;","tryCatchPattern":"try { await api.SearchAsync(filter); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"SystemTextJsonContentSerializer\"))\n{\n    // align the content serializer to System.Text.Json or use a custom query converter\n}","preventionTips":["Align the content serializer and the query converter to the same JSON stack","Add a startup assertion that the serializer matches the registered query converter","Only register SystemTextJsonQueryConverter when using SystemTextJsonContentSerializer","Document converter/serializer compatibility in your Refit configuration"],"tags":["serialization","query-converter","system-text-json","notsupported","configuration"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}