Click or drag to resize
Json.NETDeserialize with CustomCreationConverter
 
Sample
Types
 1public class Person
 2{
 3    public string FirstName { get; set; }
 4    public string LastName { get; set; }
 5    public DateTime BirthDate { get; set; }
 6}
 7
 8public class Employee : Person
 9{
10    public string Department { get; set; }
11    public string JobTitle { get; set; }
12}
13
14public class PersonConverter : CustomCreationConverter<Person>
15{
16    public override Person Create(Type objectType)
17    {
18        return new Employee();
19    }
20}
Usage
 1string json = @"{
 2  'Department': 'Furniture',
 3  'JobTitle': 'Carpenter',
 4  'FirstName': 'John',
 5  'LastName': 'Joinery',
 6  'BirthDate': '1983-02-02T00:00:00'
 7}";
 8
 9Person person = JsonConvert.DeserializeObject<Person>(json, new PersonConverter());
10
11Console.WriteLine(person.GetType().Name);
12// Employee
13
14Employee employee = (Employee)person;
15
16Console.WriteLine(employee.JobTitle);
17// Carpenter