title: JSON.NET Abstract / Derived Class Deserialization with WebAPI 2
body: <p>I'm implementing a Web API 2 service that uses JSON.NET for serialization.  </p>
  
  <p>When I try to PUT ( deseralize ) updated json data, the abstract class is not present meaning it didn't know what to do with it so it did nothing.  I also tried making the class NOT abstract and just inheriting from it and then each PUT deseralized to the base class rather than the derrived class missing the properties of the derrived class.</p>
  
  <p>Example:</p>
  
  <pre><code>public class People
  {
        // other attributes removed for demonstration simplicity
  
        public List&lt;Person&gt; People { get;set; }
  }
  
  public abstract class Person
  {
        public string Id {get;set;}
        public string Name {get;set;}
  }
  
  public class Employee : Person 
  {
        public string Badge {get;set;}
  }
  
  public class Customer : Person
  {
       public string VendorCategory {get;set;}
  }
  </code></pre>
  
  <p>with my web api configured to do typename handling:</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
       config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = 
              TypeNameHandling.Objects;
  }
  </code></pre>
  
  <p>then I PUT the JSON like:</p>
  
  <pre><code>{
       people: [{
            name: "Larry",
            id: "123",
            badge: "12345",
            $type: "API.Models.Employee, API"
       }]
  }
  </code></pre>
  
  <p>to the web api method:</p>
  
  <pre><code>public HttpResponseMessage Put(string id, [FromBody]People value)
  {
        people.Update(value); // MongoDB Repository method ( not important here )
        return Request.CreateResponse(HttpStatusCode.OK);
  }
  </code></pre>
  
  <p>but the output when inspecting <code>value</code> is always:</p>
  
  <pre><code>People == { People: [] }
  </code></pre>
  
  <p>or if non-abstract:</p>
  
  <pre><code>People == { People: [{ Name: "Larry", Id: "123" }] }
  </code></pre>
  
  <p>missing the inherrited property.  Anyone ran into this problem and come up with anything?</p>