Skip to content

Add unionKey on generated models as the first property for .NET System.Text.Json support #1315

@itsUndefined

Description

@itsUndefined

System.Text.Json in ASP.NET APIs expect the discriminator key of a union to be passed as the first parameter in the JSON for optimization reasons. Currently, freezed generated classes have the unionKey placed as the last property which is then picked up by json converter last as can be seen in the toJson generated files:

Image

I would like to have an option ( or even better be the default ) to have the generated unionKey be the first parameter. An alternative I am using now is opting out of using the unionKey and writing custom toJson methods

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions