I have a question connected with json deserilizing (Newtonsoft.Json). I don't understand the process deserialization DateTime
types and date time formatted string, in other words type string, where it is written date like this "01.01.2000" and in JObject
this field is string.
For example:
[
{
"DateOfBirth": "10.02.1990",
"SomeString": "01.12.1888"
}
]
I use the next deserialization setting:
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
MissingMemberHandling = MissingMemberHandling.Ignore,
DateParseHandling = DateParseHandling.None,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateFormatString = "dd.MM.yyyy",
Converters = new List<JsonConverter>()
{
new StringEnumConverter(),
new IsoDateTimeConverter
{
DateTimeFormat = "dd.MM.yyyy"
}
},
Error = (sender, args) =>
{
args.ErrorContext.Handled = true;
},
}
By default I expected that the first field is deserialize to DateTime
10/02/1990 00:00:00 and the second field deserialized to simple string in some object. But this is not so. Both field convert to DateTime
format.
If I set DateParseHandling.None
without IsoDateTimeConverter
the result will be next: DateTime
deserialize to null value and string will have "01.12.1888". But if I set both of this setting, everything OK.
Can someone explain this situation? And what should I do in order to get correct result without set random settings and hope for luck?