I have a web api written in aspnet webapi. The main idea is to work with inherirance. What you see here is a test project to play arround before adding this to the real project. To do that on the webconfig file i have added:
config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
Here is the model
public abstract class Person
{
public string Name { get; set; }
public string DocumentNumber { get; set; }
}
public class Teacher : Person
{
public string School { get; set; }
}
public class Employee : Person
{
public string PersonnelNumber { get; set; }
}
As a result, here is a response from the server:
[
{
"$type": "JsonConverterTest.Models.Employee, JsonConverterTest",
"PersonnelNumber": "1001",
"Name": "Emp1",
"DocumentNumber": "01"
},
{
"$type": "JsonConverterTest.Models.Employee, JsonConverterTest",
"PersonnelNumber": "1002",
"Name": "Emp2",
"DocumentNumber": "02"
},
{
"$type": "JsonConverterTest.Models.Teacher, JsonConverterTest",
"Name": "Teacher1",
"DocumentNumber": "10"
}
]
I need $type for web api deserization process to create the right instance for person.
What can i do to change the $type value to a more simple one like: "Models.Employee" or "Models.Teacher" and get rid of the assembly name?
Thanks in advance.