From 5633e17fc1436d1df02b379cbcac3e1465f4e666 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 8 Oct 2018 09:41:50 +1300 Subject: [PATCH] Fix JTokenReader not using DateTimeZoneHandling --- .../DateTimeZoneHandlingTests.cs | 2 -- Src/Newtonsoft.Json/Linq/JTokenReader.cs | 22 ++++++++++++++----- .../JsonSerializerInternalReader.cs | 5 ----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/Serialization/DateTimeZoneHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/DateTimeZoneHandlingTests.cs index 49aae922..e3778bf6 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/DateTimeZoneHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/DateTimeZoneHandlingTests.cs @@ -109,7 +109,5 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(DateTimeKind.Unspecified, c3.Value.Kind); Assert.AreEqual(DateTimeKind.Unspecified, c4.Value.Kind); } - - } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Linq/JTokenReader.cs b/Src/Newtonsoft.Json/Linq/JTokenReader.cs index a0a30eb0..c901d603 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenReader.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenReader.cs @@ -210,8 +210,16 @@ namespace Newtonsoft.Json.Linq SetToken(JsonToken.Undefined, ((JValue)token).Value); break; case JTokenType.Date: - SetToken(JsonToken.Date, ((JValue)token).Value); - break; + { + object v = ((JValue)token).Value; + if (v is DateTime dt) + { + v = DateTimeUtils.EnsureDateTime(dt, DateTimeZoneHandling); + } + + SetToken(JsonToken.Date, v); + break; + } case JTokenType.Raw: SetToken(JsonToken.Raw, ((JValue)token).Value); break; @@ -222,10 +230,12 @@ namespace Newtonsoft.Json.Linq SetToken(JsonToken.String, SafeToString(((JValue)token).Value)); break; case JTokenType.Uri: - object v = ((JValue)token).Value; - Uri uri = v as Uri; - SetToken(JsonToken.String, uri != null ? uri.OriginalString : SafeToString(v)); - break; + { + object v = ((JValue)token).Value; + Uri uri = v as Uri; + SetToken(JsonToken.String, uri != null ? uri.OriginalString : SafeToString(v)); + break; + } case JTokenType.TimeSpan: SetToken(JsonToken.String, SafeToString(((JValue)token).Value)); break; diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index 2b354c0a..23923262 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -990,11 +990,6 @@ namespace Newtonsoft.Json.Serialization } } - if (value is DateTime dt) - { - return DateTimeUtils.EnsureDateTime(dt, reader.DateTimeZoneHandling); - } - return value; }