Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The polymorphism in C# with Newtonsoft.Json is unable to deserialize child classes due to the JsonConverter annotation present in the child class. #17990

Open
npottiez opened this issue Feb 28, 2024 · 2 comments

Comments

@npottiez
Copy link

npottiez commented Feb 28, 2024

"Adding [JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")] to the child C# class compels Newtonsoft to not look at the subtypes within the child class. To do it properly, one should move the line [JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")] in {{#mappedModels.length}}.
like this ?
{{#mappedModels.length}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
{{/mappedModels.length}}

https://github.com/OpenAPITools/openapi-generator/blame/275ed9296dea4a1a894cc5b3402b5b8f3a61e7d7/modules/openapi-generator/src/main/resources/csharp/modelGeneric.mustache#L13

@wing328
Copy link
Member

wing328 commented Mar 1, 2024

can you please file a PR with the suggested fix?

@DaveK-Rocketmakers
Copy link
Contributor

I've been hit by this issue recently. Raised #19972 with an adaption on the suggested change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants