I am trying to deserialize a string content into an object, but I want the content to be case sensitive. The code should only succeed if the string has lower case properties and fail if it has upper case properties. Following is the class:
internal class ResponseList
{
[DataMember]
[JsonProperty]
internal List<Response> Value { get; set; }
}
internal class Response
{
[DataMember]
[JsonProperty]
internal string Id { get; set; }
[DataMember]
[JsonProperty]
internal string Location { get; set; }
[DataMember]
[JsonProperty]
internal PlanClass Plan { get; set; }
}
internal class PlanClass
{
[DataMember]
[JsonProperty]
internal string Name { get; set; }
[DataMember]
[JsonProperty]
internal string Product { get; set; }
[DataMember]
[JsonProperty]
internal string Publisher { get; set; }
}
Following is the code I have. But this is not case-sensitive. It is succeeding for both upper and lowercase:
string content = File.ReadAllText(contentFilePath);
JsonSerializerSettings jsonSerializerSettings1 = new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
ResponseList response = (ResponseList)JsonConvert.DeserializeObject(contentResourceOutput, typeof(ResponseList), Constants.JsonSerializerSettings);
The code should only succeed if the content is:
{
"value": [
{
"id": "id1",
"location": "location1",
"plan": {
"name": "free",
"product": "product1",
"publisher": "publisher1"
}
}
]
}
and fail if even if one of the keys is uppercase. E.g.
{
"value": [
{
"Id": "id1",
"Location": "location1",
"plan": {
"Name": "free",
"product": "product1",
"publisher": "publisher1"
}
}
]
}
Notice that only the Keys/Property names should be lower case. The values can be upper case. Is there a way to make JsonConvert.Deserializeobject case sensitive?