Repository navigation
Conversation
JsonStringEnumConverter matches every enum type and System.Text.Json uses the first matching converter registered in JsonSerializerOptions.Converters, so registering it before the generated schema-specific enum converters shadowed them. Enum arrays and standalone enums were serialized with C# member names instead of the wire values declared by the schema. Register the generic converter after the generated per-schema converters, add a generator regression test asserting the order, and regenerate the csharp-generichost samples. Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
Member
|
thanks for the PR cc @devhl-labs |
This branch has not been deployed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
In the C# generichost client,
HostConfigurationregistered the genericJsonStringEnumConverterbefore the generated schema-specific enum converters.JsonStringEnumConverter.CanConvertmatches every enum type and System.Text.Json uses the first matching converter registered inJsonSerializerOptions.Converters, so the generatedXJsonConverter/XNullableJsonConverterconverters were never selected for standalone enums or enum arrays. Integer enum arrays were serialized as C# member names and string enum arrays whose wire values differ from the member names violated the schema.Fixes #25206
Fix
Register the generic
JsonStringEnumConverterafter the generated per-schema converters, so specific converters take precedence and the generic one still covers enums without a generated converter. This is the same mechanism as the workaround verified in the issue (removing and re-adding the generic converter to move it last), now applied at the template level.Related: #21393 reports the same converter registration order (this fix addresses its root cause), and #22917 previously corrected the generated numeric enum converters' read/write implementation, which the ordering problem prevented from being selected for array elements.
Tests
testGenericHostRegistersGenericStringEnumConverterLastasserting the generated per-enum converters appear beforenew JsonStringEnumConverter()in the generatedHostConfiguration.cs(33 tests inCSharpClientCodegenTest, 0 failures).PR checklist
master.Summary by cubic
Fixes the C# generichost client's enum serialization by registering the generic
JsonStringEnumConverterafter the generated schema-specific converters, so the generated converters are used for enums and enum arrays. Previously the generic converter shadowed them, causing enum arrays and standalone enums to serialize with C# member names instead of the wire values defined by the schema. Also adds a regression test asserting the registration order and regenerates the affected samples.Written for commit c9ebf04. Summary will update on new commits.