-Fixed writing ULong.MaxValue JValues as JSON

This commit is contained in:
James Newton-King
2015-06-12 09:59:20 +12:00
parent 1ba98761c7
commit b270104bfb
2 changed files with 40 additions and 2 deletions
@@ -54,6 +54,38 @@ namespace Newtonsoft.Json.Tests.Linq
[TestFixture]
public class LinqToJsonTest : TestFixtureBase
{
public class TestClass_ULong
{
public ulong Value { get; set; }
}
[Test]
public void FromObject_ULongMaxValue()
{
TestClass_ULong instance = new TestClass_ULong { Value = ulong.MaxValue };
JObject output = JObject.FromObject(instance);
StringAssert.AreEqual(@"{
""Value"": 18446744073709551615
}", output.ToString());
}
public class TestClass_Byte
{
public byte Value { get; set; }
}
[Test]
public void FromObject_ByteMaxValue()
{
TestClass_Byte instance = new TestClass_Byte { Value = byte.MaxValue };
JObject output = JObject.FromObject(instance);
StringAssert.AreEqual(@"{
""Value"": 255
}", output.ToString());
}
[Test]
public void ToObject_Base64AndGuid()
{
+8 -2
View File
@@ -676,11 +676,17 @@ namespace Newtonsoft.Json.Linq
writer.WriteUndefined();
return;
case JTokenType.Integer:
if (_value is int)
writer.WriteValue((int)_value);
else if (_value is long)
writer.WriteValue((long)_value);
else if (_value is ulong)
writer.WriteValue((ulong)_value);
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
if (_value is BigInteger)
else if (_value is BigInteger)
writer.WriteValue((BigInteger)_value);
else
#endif
else
writer.WriteValue(Convert.ToInt64(_value, CultureInfo.InvariantCulture));
return;
case JTokenType.Float: