title: .net 6.0 Core migration changes JSON from framework. Polymorphism restriction
body: <p>We're migrating a .net 4.7 framework solution to .net 6.0 (core). The solution interfaces with a React front-end system, and a NodeJS MongoDb back-end, so we have gone with the MVC model and copied our code to new projects.</p>
  <p>Our problem is the change in design relating the the JSON controller response. In the live system, the JSON sent to the external system is fully resolved to the polymorphic version, while in the new core system it is resolved to the base class. Here's a snip of the response class:<a href="https://i.stack.imgur.com/XbPmI.png" rel="nofollow noreferrer">class start showing interface used to send the screen data to display</a></p>
  <p>Postman shows us that when we have the interface swapped with a base class, the JSON response is the base class. Interestingly, swapping it for an interface has the default JSON response (System.Text.Json) use the properties in the interface, while Newtonsoft.Json correctly renders the full/inherited class with JsonConvert.SerializeObject() versus JsonSerializer.Serialize().</p>
  <p>We have changed the Program.cs to include &quot;services.AddControllers().AddNewtonsoftJson();&quot; which seems to get past our problem so far, but I'm assuming it should be possible to use the new library instead. Performance isn't an issue, but we are upgrading to stay on a strategic path.</p>
  <p>We have looked at explanations like <a href="https://www.tutorialdocs.com/article/webapi-data-binding.html" rel="nofollow noreferrer">https://www.tutorialdocs.com/article/webapi-data-binding.html</a> and <a href="https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-polymorphism" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-polymorphism</a> but don't know the best way forward. Get rid of polymophism (composition instead of inheritance?) But then our system just exported the interface properties. We've also tried to validate our System.Runtime.Serialization annotations, but without success.</p>
  <p>We'd appreciate guidance on a good approach to solve this.</p>