Need to handle duplicate property names in incoming json to Asp.Net Web API. Accordingly such json needs to be rejected in first place.
Below is the input json:
{
"OId":"OId-1",
"OId":"OId-2",
"Addresses":[
{
"Prop1":"PROP-1",
"Prop2":"PROP-2",
},
{
"Prop1":"PROP-1",
"Prop2":"PROP-2",
},
],
"Addresses":[
{
"Prop1":"PROP-1",
"Prop2":"PROP-2",
},
],}
C# Object to be desterilized to:
public class Person
{
public string OId { get; set; }
public List<Address> Addresses { get; set; }
}
public class Address
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
Concern: Newtonsoft.Json ignores these duplicate values and deserialises to:
person.OId ="OId-2";Addresses->Count = 3;
Taking the latest property name and value. And in terms of Arrays it combines them to form a single array.In above case 3.