-Fixed JValue.WriteTo losing type information with JTokenWriter

This commit is contained in:
James Newton-King
2016-04-29 19:18:06 +12:00
parent 5b04a61dd9
commit 092dc7da58
2 changed files with 22 additions and 2 deletions
@@ -55,6 +55,24 @@ namespace Newtonsoft.Json.Tests.Linq
[TestFixture]
public class LinqToJsonTest : TestFixtureBase
{
[Test]
public void FromObjectGuid()
{
var token1 = new JValue(Guid.NewGuid());
var token2 = JToken.FromObject(token1);
Assert.IsTrue(JToken.DeepEquals(token1, token2));
Assert.AreEqual(token1.Type, token2.Type);
}
[Test]
public void FromObjectTimeSpan()
{
var token1 = new JValue(TimeSpan.FromDays(1));
var token2 = JToken.FromObject(token1);
Assert.IsTrue(JToken.DeepEquals(token1, token2));
Assert.AreEqual(token1.Type, token2.Type);
}
[Test]
public void ToObject_Guid()
{
+4 -2
View File
@@ -819,11 +819,13 @@ namespace Newtonsoft.Json.Linq
writer.WriteValue((byte[])_value);
return;
case JTokenType.Guid:
writer.WriteValue((_value != null) ? (Guid?)_value : null);
return;
case JTokenType.TimeSpan:
writer.WriteValue((_value != null) ? _value.ToString() : null);
writer.WriteValue((_value != null) ? (TimeSpan?)_value : null);
return;
case JTokenType.Uri:
writer.WriteValue((_value != null) ? ((Uri)_value).OriginalString : null);
writer.WriteValue((Uri)_value);
return;
}