Reputation: 757
I want to understand how Json.NET deserializes a JSON object to corresponding c# object when we have multiple property names with different cases(I know this is not a good practice, but just curious to know how JSON.NET deals with this).
I have a c# object defined as below:
public class TestModel
{
public string Name { get; set; }
public bool IsEmployee { get; set; }
}
And json object as
{ "Name": "TestName","Isemployee":true, "isemployee":false};
Then, if I use the JSON.NET de-serialize method to convert above json string to TestModel object, which one of those two properties will be assigned to IsEmployee
variable? And why?
Thanks.
Upvotes: 4
Views: 2529
Reputation: 15981
In deserialization, Json.NET attempts case insensitive matching of an attribute if exact matching fails, as discussed here. This is in contrast to the built-in .NET JSON serializers, see here.
If multiple matches are detected, the last match takes precedence.
Upvotes: 2