OpenAPITools / OpenAPITools/openapi-generator
The polymorphism in C# with Newtonsoft.Json is unable to deserialize child classes due to the JsonConverter annotation present in the child class.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
"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}}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The referenced template is modules/openapi-generator/src/main/resources/csharp/modelGeneric.mustache near line 13; inspect how JsonConverter is emitted for child and mapped models. Regenerate a C# client from a polymorphic OpenAPI model and verify Newtonsoft.Json can deserialize child classes without the child annotation blocking subtype lookup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100