JSOND-sensitive deserialization

Can I specify some deserialization options to perform case-sensitive deserialization using Json.NET ?

Suggest:

public class Account { public string Email { get; set; } public bool Active { get; set; } public DateTime CreatedDate { get; set; } public IList<string> Roles { get; set; } } 

should fail when deserializing from:

 { "email": " james@example.com ", "active": true, "createdDate": "2013-01-20T00:00:00Z", "roles": [ "User", "Admin" ] } 
+5
source share
1 answer

Most likely, unfortunately. It seems to be hard-coded to a random register, case insensitive.

 /// <summary> /// Gets the closest matching <see cref="JsonProperty"/> object. /// First attempts to get an exact case match of propertyName and then /// a case insensitive match. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <returns>A matching property if found.</returns> public JsonProperty GetClosestMatchProperty(string propertyName) { JsonProperty property = GetProperty(propertyName, StringComparison.Ordinal); if (property == null) { property = GetProperty(propertyName, StringComparison.OrdinalIgnoreCase); } return property; } 

JsonPropertyCollection

This is caused by the internal reader, so there is no simple switch that you could just flip over. This should be possible, but you will have to write the converter yourself to reject case-insensitive matches.

+8
source

Source: https://habr.com/ru/post/1239676/


All Articles