Fix losing DateTime.Kind when deserializing ISO date strings (#1727)
This commit is contained in:
@@ -953,15 +953,23 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
if (contract.IsEnum)
|
||||
{
|
||||
if (value is string)
|
||||
if (value is string s)
|
||||
{
|
||||
return EnumUtils.ParseEnum(contract.NonNullableUnderlyingType, value.ToString(), false);
|
||||
return EnumUtils.ParseEnum(contract.NonNullableUnderlyingType, s, false);
|
||||
}
|
||||
if (ConvertUtils.IsInteger(primitiveContract.TypeCode))
|
||||
{
|
||||
return Enum.ToObject(contract.NonNullableUnderlyingType, value);
|
||||
}
|
||||
}
|
||||
else if (contract.NonNullableUnderlyingType == typeof(DateTime))
|
||||
{
|
||||
// use DateTimeUtils because Convert.ChangeType does not set DateTime.Kind correctly
|
||||
if (value is string s && DateTimeUtils.TryParseDateTime(s, reader.DateTimeZoneHandling, reader.DateFormatString, reader.Culture, out DateTime dt))
|
||||
{
|
||||
return DateTimeUtils.EnsureDateTime(dt, reader.DateTimeZoneHandling);
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_BIG_INTEGER
|
||||
if (value is BigInteger integer)
|
||||
|
||||
Reference in New Issue
Block a user