title: Json.Net Serialization of Type with Polymorphic Child Object
body: <p>We would like to be able to serialize/deserialize json from/to C# classes, with the main class having an instance of a polymorphic child object. Doing so is easy using Json.Net's TypeNameHandling.Auto setting. However, we would like to do so without the "$type" field.</p>
  
  <p>The first thought is to be able to rename "$type" to a value of our choosing and to have the value for the type be an enum that would map the sub-types properly. I have not seen that as being an option but would be glad to hear if it is possible.</p>
  
  <p>The second thought was along the following lines... Below is a first pass at classes, with the top level class having an indicator (SubTypeType) as to what type of data is contained in the child object (SubTypeData). I've dug around a bit into the Json.Net documentation and have tried a few things but have had no luck.</p>
  
  <p>We currently have full control over the data definition, but once it is deployed, then things are locked.</p>
  
  <pre><code>public class MainClass
  {
    public SubType          SubTypeType { get; set; }
    public SubTypeClassBase SubTypeData { get; set; }
  }
  
  public class SubTypeClassBase
  {
  }
  
  public class SubTypeClass1 : SubTypeClassBase
  {
    public string AaaField { get; set; }
  }
  
  public class SubTypeClass2 : SubTypeClassBase
  {
    public string ZzzField { get; set; }
  }
  </code></pre>