Skip to content

JsonSerializerContext source generator ignores Converters #116684

Open
@johnwc

Description

@johnwc

Description

Trying to figure out why my code keeps failing, and it when looking further into the generated code, there seems to be no converter being added to the Default context property. It has a count of 0 no matter how I try to use it.

[JsonSourceGenerationOptions(
    GenerationMode = JsonSourceGenerationMode.Default,
    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
    Converters = [
        typeof(AccountId.AccountIdSystemTextJsonConverter)
        ])]
[JsonSerializable(typeof(AccountMembership))]
[JsonSerializable(typeof(AccountId))]
public partial class SourceGenerationContext : JsonSerializerContext
{
}

Reproduction Steps

Create SourceGenerationContext using the shared code above.
View that the Default.Optons.Converters is empty.

Expected behavior

The list of converters given in the JsonSourceGenerationOptions attribute be set within the Default options. for the context

Actual behavior

No converters added.

Regression?

No response

Known Workarounds

No response

Configuration

.Net 9.0.6

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions