I have a class as follows.
[Datacontract]
public class Customer
{
[DataMember(Name="p1")]
public string Name { get; set; }
[DataMember(Name = "p2")]
public string SurName { get; set; }
}
Case 1:
json:{"Name":"John","SurName":"Asdf"}
Deserialized object: customer.Name => null and customer.SurName => null
Case 2
Json: {"p1":"John","p2":"Asdf"}
Deserialized object: customer.Name => John and customer.SurName=> Asdf
Problem:
I have the json in Case1 => {"Name":"John","SurName":"Asdf"}
I wait the deserialized object in Case2 =>
customer.Name => John and customer.SurName=> Asdf
So, How I can provide during deserialization that ignore DataMember(Name) attribute?
Solved:
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
property.PropertyName = member.Name;
return property;
}
Thank you @dbc