using Newtonsoft.Json.Serialization;
public static void Main()
public static void TestCase1()
var result = JsonConvert.DeserializeObject<Response<Employee>>(json,new JsonSerializerSettings { ContractResolver = new GenericContractResolver<Employee>() });
public static void TestCase2()
var result = JsonConvert.DeserializeObject<Response<Student>>(json,new JsonSerializerSettings { ContractResolver = new GenericContractResolver<Student>() });
public class GenericContractResolver<T> : DefaultContractResolver
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
var property = base.CreateProperty(member, memberSerialization);
if (property.UnderlyingName == nameof(Response<T>.Item))
foreach( var attribute in System.Attribute.GetCustomAttributes(typeof(T)))
if(attribute is JsonObjectAttribute jobject)
property.PropertyName = jobject.Title;
public class Response<T> {
[JsonProperty(PropertyName = "status")]
public bool Status {get;set;}
[JsonObject(Title = "employee")]
[JsonProperty(PropertyName = "firstName")]
public string FirstName {get; set;}
[JsonProperty(PropertyName = "lastName")]
public string LastName {get; set;}
[JsonObject(Title = "student")]
[JsonProperty(PropertyName = "fullname")]
public string FullName {get; set;}
[JsonProperty(PropertyName = "age")]
public int Age {get; set;}