-Added FloatParseHandling
-Fixed build
This commit is contained in:
@@ -95,7 +95,56 @@ namespace Newtonsoft.Json.Tests.Bson
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteValues()
|
||||
public void ReadDouble()
|
||||
{
|
||||
byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
|
||||
|
||||
MemoryStream ms = new MemoryStream(data);
|
||||
BsonReader reader = new BsonReader(ms);
|
||||
reader.ReadRootValueAsArray = true;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(99.99d, reader.Value);
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
Assert.AreEqual(JsonToken.None, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadDouble_Decimal()
|
||||
{
|
||||
byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
|
||||
|
||||
MemoryStream ms = new MemoryStream(data);
|
||||
BsonReader reader = new BsonReader(ms);
|
||||
reader.FloatParseHandling = FloatParseHandling.Decimal;
|
||||
reader.ReadRootValueAsArray = true;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(99.99m, reader.Value);
|
||||
Assert.AreEqual(typeof(decimal), reader.ValueType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
Assert.AreEqual(JsonToken.None, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadValues()
|
||||
{
|
||||
byte[] data = MiscellaneousUtils.HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
|
||||
MemoryStream ms = new MemoryStream(data);
|
||||
@@ -184,7 +233,6 @@ namespace Newtonsoft.Json.Tests.Bson
|
||||
Assert.AreEqual(JsonToken.None, reader.TokenType);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ReadObjectBsonFromSite()
|
||||
{
|
||||
|
||||
@@ -114,6 +114,20 @@ namespace Newtonsoft.Json.Tests.Bson
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void WriteDouble()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BsonWriter writer = new BsonWriter(ms);
|
||||
|
||||
writer.WriteStartArray();
|
||||
writer.WriteValue(99.99d);
|
||||
writer.WriteEnd();
|
||||
|
||||
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
|
||||
Assert.AreEqual("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00", bson);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteArrayBsonFromSite()
|
||||
{
|
||||
|
||||
@@ -44,6 +44,57 @@ namespace Newtonsoft.Json.Tests
|
||||
[TestFixture]
|
||||
public class JsonTextReaderTest : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void FloatParseHandling()
|
||||
{
|
||||
string json = "[1.0,1,9.9,1E-06]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(1.0d, reader.Value);
|
||||
Assert.AreEqual(typeof(decimal), reader.ValueType);
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(1, reader.Value);
|
||||
Assert.AreEqual(typeof(long), reader.ValueType);
|
||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(9.9d, reader.Value);
|
||||
Assert.AreEqual(typeof(decimal), reader.ValueType);
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(Convert.ToDecimal(1E-06), reader.Value);
|
||||
Assert.AreEqual(typeof(decimal), reader.ValueType);
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FloatParseHandling_NaN()
|
||||
{
|
||||
string json = "[NaN]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"Cannot read NaN as a decimal.",
|
||||
() => reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnescapeDoubleQuotes()
|
||||
{
|
||||
|
||||
@@ -50,6 +50,19 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[TestFixture]
|
||||
public class JValueTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void FloatParseHandling()
|
||||
{
|
||||
JValue v = (JValue) JToken.ReadFrom(
|
||||
new JsonTextReader(new StringReader("9.9"))
|
||||
{
|
||||
FloatParseHandling = Json.FloatParseHandling.Decimal
|
||||
});
|
||||
|
||||
Assert.AreEqual(9.9d, v.Value);
|
||||
Assert.AreEqual(typeof(decimal), v.Value.GetType());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChangeValue()
|
||||
{
|
||||
|
||||
@@ -75,4 +75,4 @@ using System.Security;
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.0.1.15924")]
|
||||
[assembly: AssemblyFileVersion("5.0.1.15926")]
|
||||
|
||||
@@ -3908,6 +3908,21 @@ To fix this error either change the environment to be fully trusted, change the
|
||||
Assert.AreEqual(null, cc.Ignored);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeFloatAsDecimal()
|
||||
{
|
||||
string json = @"{'value':9.9}";
|
||||
|
||||
var dic = JsonConvert.DeserializeObject<IDictionary<string, object>>(
|
||||
json, new JsonSerializerSettings
|
||||
{
|
||||
FloatParseHandling = FloatParseHandling.Decimal
|
||||
});
|
||||
|
||||
Assert.AreEqual(typeof(decimal), dic["value"].GetType());
|
||||
Assert.AreEqual(9.9d, dic["value"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldSerializeTest()
|
||||
{
|
||||
@@ -6765,6 +6780,41 @@ Parameter name: value",
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeFloatingPointHandling()
|
||||
{
|
||||
string json;
|
||||
IList<double> d = new List<double> {1.1, double.NaN, double.PositiveInfinity};
|
||||
|
||||
json = JsonConvert.SerializeObject(d);
|
||||
// [1.1,"NaN","Infinity"]
|
||||
|
||||
json = JsonConvert.SerializeObject(d, new JsonSerializerSettings { FloatFormatHandling = FloatFormatHandling.Symbol });
|
||||
// [1.1,NaN,Infinity]
|
||||
|
||||
json = JsonConvert.SerializeObject(d, new JsonSerializerSettings {FloatFormatHandling = FloatFormatHandling.DefaultValue});
|
||||
// [1.1,0.0,0.0]
|
||||
|
||||
Assert.AreEqual("[1.1,0.0,0.0]", json);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || NET40 || PORTABLE || SILVERLIGHT)
|
||||
[Test]
|
||||
public void DeserializeReadOnlyListWithBigInteger()
|
||||
{
|
||||
string json = @"[
|
||||
9000000000000000000000000000000000000000000000000
|
||||
]";
|
||||
|
||||
var l = JsonConvert.DeserializeObject<IReadOnlyList<BigInteger>>(json);
|
||||
|
||||
BigInteger nineQuindecillion = l[0];
|
||||
// 9000000000000000000000000000000000000000000000000
|
||||
|
||||
Assert.AreEqual(BigInteger.Parse("9000000000000000000000000000000000000000000000000"), nineQuindecillion);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void SerializeCustomTupleWithSerializableAttribute()
|
||||
{
|
||||
@@ -7500,6 +7550,7 @@ Parameter name: value",
|
||||
}", json);
|
||||
}
|
||||
|
||||
#if !(PORTABLE || NET35 || NET20 || SILVERLIGHT)
|
||||
[Test]
|
||||
public void ReadTooLargeInteger()
|
||||
{
|
||||
@@ -7513,6 +7564,7 @@ Parameter name: value",
|
||||
"Error converting value 999999999999999999999999999999999999999999999999 to type 'System.Int64'. Path '[0]', line 1, position 49.",
|
||||
() => JsonConvert.DeserializeObject<IList<long>>(json));
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void ReadStringFloatingPointSymbols()
|
||||
|
||||
@@ -504,7 +504,12 @@ namespace Newtonsoft.Json.Bson
|
||||
switch (type)
|
||||
{
|
||||
case BsonType.Number:
|
||||
SetToken(JsonToken.Float, ReadDouble());
|
||||
double d = ReadDouble();
|
||||
|
||||
if (_floatParseHandling == FloatParseHandling.Decimal)
|
||||
SetToken(JsonToken.Float, Convert.ToDecimal(d, CultureInfo.InvariantCulture));
|
||||
else
|
||||
SetToken(JsonToken.Float, d);
|
||||
break;
|
||||
case BsonType.String:
|
||||
case BsonType.Symbol:
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies float format handling options when writing special floating point values, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// Specifies float format handling options when writing special floating point numbers, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// <see cref="F:System.Double.PositiveInfinity"/> and <see cref="F:System.Double.NegativeInfinity"/> with <see cref="JsonWriter"/>.
|
||||
/// </summary>
|
||||
public enum FloatFormatHandling
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies how floating point numbers, e.g. 1.0 and 9.9, are parsed when reading JSON text.
|
||||
/// </summary>
|
||||
public enum FloatParseHandling
|
||||
{
|
||||
/// <summary>
|
||||
/// Floating point numbers are parsed to <see cref="Double"/>.
|
||||
/// </summary>
|
||||
Double,
|
||||
/// <summary>
|
||||
/// Floating point numbers are parsed to <see cref="Decimal"/>.
|
||||
/// </summary>
|
||||
Decimal
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,7 @@ namespace Newtonsoft.Json
|
||||
private int? _maxDepth;
|
||||
private bool _hasExceededMaxDepth;
|
||||
internal DateParseHandling _dateParseHandling;
|
||||
internal FloatParseHandling _floatParseHandling;
|
||||
private readonly List<JsonPosition> _stack;
|
||||
|
||||
/// <summary>
|
||||
@@ -160,6 +161,15 @@ namespace Newtonsoft.Json
|
||||
set { _dateParseHandling = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how floating point numbers, e.g. 1.0 and 9.9, are parsed when reading JSON text.
|
||||
/// </summary>
|
||||
public FloatParseHandling FloatParseHandling
|
||||
{
|
||||
get { return _floatParseHandling; }
|
||||
set { _floatParseHandling = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a <see cref="JsonReaderException"/>.
|
||||
/// </summary>
|
||||
@@ -263,6 +273,7 @@ namespace Newtonsoft.Json
|
||||
_stack = new List<JsonPosition>(4);
|
||||
_dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
|
||||
_dateParseHandling = DateParseHandling.DateTime;
|
||||
_floatParseHandling = FloatParseHandling.Double;
|
||||
|
||||
CloseInput = true;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace Newtonsoft.Json
|
||||
private DateTimeZoneHandling? _dateTimeZoneHandling;
|
||||
private DateParseHandling? _dateParseHandling;
|
||||
private FloatFormatHandling? _floatFormatHandling;
|
||||
private FloatParseHandling? _floatParseHandling;
|
||||
private StringEscapeHandling? _stringEscapeHandling;
|
||||
private CultureInfo _culture;
|
||||
private int? _maxDepth;
|
||||
@@ -347,9 +348,18 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how special floating point values, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// Get or set how floating point numbers, e.g. 1.0 and 9.9, are parsed when reading JSON text.
|
||||
/// </summary>
|
||||
public virtual FloatParseHandling FloatParseHandling
|
||||
{
|
||||
get { return _floatParseHandling ?? JsonSerializerSettings.DefaultFloatParseHandling; }
|
||||
set { _floatParseHandling = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how special floating point numbers, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// <see cref="F:System.Double.PositiveInfinity"/> and <see cref="F:System.Double.NegativeInfinity"/>,
|
||||
/// are written as JSON.
|
||||
/// are written as JSON text.
|
||||
/// </summary>
|
||||
public virtual FloatFormatHandling FloatFormatHandling
|
||||
{
|
||||
@@ -476,6 +486,7 @@ namespace Newtonsoft.Json
|
||||
jsonSerializer._dateFormatString = settings._dateFormatString;
|
||||
jsonSerializer._dateFormatStringSet = settings._dateFormatStringSet;
|
||||
jsonSerializer._floatFormatHandling = settings._floatFormatHandling;
|
||||
jsonSerializer._floatParseHandling = settings._floatParseHandling;
|
||||
jsonSerializer._stringEscapeHandling = settings._stringEscapeHandling;
|
||||
jsonSerializer._culture = settings._culture;
|
||||
jsonSerializer._maxDepth = settings._maxDepth;
|
||||
@@ -598,6 +609,13 @@ namespace Newtonsoft.Json
|
||||
reader.DateParseHandling = _dateParseHandling.Value;
|
||||
}
|
||||
|
||||
FloatParseHandling? previousFloatParseHandling = null;
|
||||
if (_floatParseHandling != null && reader.FloatParseHandling != _floatParseHandling)
|
||||
{
|
||||
previousFloatParseHandling = reader.FloatParseHandling;
|
||||
reader.FloatParseHandling = _floatParseHandling.Value;
|
||||
}
|
||||
|
||||
int? previousMaxDepth = null;
|
||||
if (_maxDepthSet && reader.MaxDepth != _maxDepth)
|
||||
{
|
||||
@@ -615,6 +633,8 @@ namespace Newtonsoft.Json
|
||||
reader.DateTimeZoneHandling = previousDateTimeZoneHandling.Value;
|
||||
if (previousDateParseHandling != null)
|
||||
reader.DateParseHandling = previousDateParseHandling.Value;
|
||||
if (previousFloatParseHandling != null)
|
||||
reader.FloatParseHandling = previousFloatParseHandling.Value;
|
||||
if (_maxDepthSet)
|
||||
reader.MaxDepth = previousMaxDepth;
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace Newtonsoft.Json
|
||||
internal const DateFormatHandling DefaultDateFormatHandling = DateFormatHandling.IsoDateFormat;
|
||||
internal const DateTimeZoneHandling DefaultDateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
|
||||
internal const DateParseHandling DefaultDateParseHandling = DateParseHandling.DateTime;
|
||||
internal const FloatParseHandling DefaultFloatParseHandling = FloatParseHandling.Double;
|
||||
internal const FloatFormatHandling DefaultFloatFormatHandling = FloatFormatHandling.String;
|
||||
internal const StringEscapeHandling DefaultStringEscapeHandling = StringEscapeHandling.Default;
|
||||
internal static readonly CultureInfo DefaultCulture;
|
||||
@@ -63,6 +64,7 @@ namespace Newtonsoft.Json
|
||||
internal DateTimeZoneHandling? _dateTimeZoneHandling;
|
||||
internal DateParseHandling? _dateParseHandling;
|
||||
internal FloatFormatHandling? _floatFormatHandling;
|
||||
internal FloatParseHandling? _floatParseHandling;
|
||||
internal StringEscapeHandling? _stringEscapeHandling;
|
||||
internal CultureInfo _culture;
|
||||
internal bool? _checkAdditionalContent;
|
||||
@@ -234,7 +236,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how special floating point values, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// Get or set how special floating point numbers, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// <see cref="F:System.Double.PositiveInfinity"/> and <see cref="F:System.Double.NegativeInfinity"/>,
|
||||
/// are written as JSON.
|
||||
/// </summary>
|
||||
@@ -244,6 +246,15 @@ namespace Newtonsoft.Json
|
||||
set { _floatFormatHandling = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how floating point numbers, e.g. 1.0 and 9.9, are parsed when reading JSON text.
|
||||
/// </summary>
|
||||
public FloatParseHandling FloatParseHandling
|
||||
{
|
||||
get { return _floatParseHandling ?? DefaultFloatParseHandling; }
|
||||
set { _floatParseHandling = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how strings are escaped when writing JSON text.
|
||||
/// </summary>
|
||||
|
||||
@@ -1243,7 +1243,11 @@ namespace Newtonsoft.Json
|
||||
// it's faster to do 3 indexof with single characters than an indexofany
|
||||
if (number.IndexOf('.') != -1 || number.IndexOf('E') != -1 || number.IndexOf('e') != -1)
|
||||
{
|
||||
numberValue = Convert.ToDouble(number, CultureInfo.InvariantCulture);
|
||||
if (_floatParseHandling == FloatParseHandling.Decimal)
|
||||
numberValue = decimal.Parse(number, NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture);
|
||||
else
|
||||
numberValue = Convert.ToDouble(number, CultureInfo.InvariantCulture);
|
||||
|
||||
numberType = JsonToken.Float;
|
||||
}
|
||||
else
|
||||
@@ -1452,6 +1456,9 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
if (MatchValueWithTrailingSeperator(JsonConvert.NegativeInfinity))
|
||||
{
|
||||
if (_floatParseHandling == FloatParseHandling.Decimal)
|
||||
throw new JsonReaderException("Cannot read -Infinity as a decimal.");
|
||||
|
||||
SetToken(JsonToken.Float, double.NegativeInfinity);
|
||||
}
|
||||
else
|
||||
@@ -1464,6 +1471,9 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
if (MatchValueWithTrailingSeperator(JsonConvert.PositiveInfinity))
|
||||
{
|
||||
if (_floatParseHandling == FloatParseHandling.Decimal)
|
||||
throw new JsonReaderException("Cannot read Infinity as a decimal.");
|
||||
|
||||
SetToken(JsonToken.Float, double.PositiveInfinity);
|
||||
}
|
||||
else
|
||||
@@ -1476,6 +1486,9 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
if (MatchValueWithTrailingSeperator(JsonConvert.NaN))
|
||||
{
|
||||
if (_floatParseHandling == FloatParseHandling.Decimal)
|
||||
throw new JsonReaderException("Cannot read NaN as a decimal.");
|
||||
|
||||
SetToken(JsonToken.Float, double.NaN);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how special floating point values, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// Get or set how special floating point numbers, e.g. <see cref="F:System.Double.NaN"/>,
|
||||
/// <see cref="F:System.Double.PositiveInfinity"/> and <see cref="F:System.Double.NegativeInfinity"/>,
|
||||
/// are written to JSON text.
|
||||
/// </summary>
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<Compile Include="DateParseHandling.cs" />
|
||||
<Compile Include="DateTimeZoneHandling.cs" />
|
||||
<Compile Include="FloatFormatHandling.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="FormatterAssemblyStyle.cs" />
|
||||
<Compile Include="Formatting.cs" />
|
||||
<Compile Include="JsonConstructorAttribute.cs" />
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
<Compile Include="DateParseHandling.cs" />
|
||||
<Compile Include="DateTimeZoneHandling.cs" />
|
||||
<Compile Include="FloatFormatHandling.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="FormatterAssemblyStyle.cs" />
|
||||
<Compile Include="Formatting.cs" />
|
||||
<Compile Include="JsonConstructorAttribute.cs" />
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
<Compile Include="ConstructorHandling.cs" />
|
||||
<Compile Include="Converters\VersionConverter.cs" />
|
||||
<Compile Include="FloatFormatHandling.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="JsonDictionaryAttribute.cs" />
|
||||
<Compile Include="JsonException.cs" />
|
||||
<Compile Include="DateFormatHandling.cs" />
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<Compile Include="DateTimeZoneHandling.cs" />
|
||||
<Compile Include="DefaultValueHandling.cs" />
|
||||
<Compile Include="FloatFormatHandling.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="FormatterAssemblyStyle.cs" />
|
||||
<Compile Include="Formatting.cs" />
|
||||
<Compile Include="IJsonLineInfo.cs" />
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
<Compile Include="DateParseHandling.cs" />
|
||||
<Compile Include="DateTimeZoneHandling.cs" />
|
||||
<Compile Include="FloatFormatHandling.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="FormatterAssemblyStyle.cs" />
|
||||
<Compile Include="DefaultValueHandling.cs" />
|
||||
<Compile Include="Formatting.cs" />
|
||||
|
||||
@@ -138,6 +138,7 @@
|
||||
<Compile Include="DateTimeZoneHandling.cs" />
|
||||
<Compile Include="FloatFormatHandling.cs" />
|
||||
<Compile Include="DefaultValueHandling.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="FormatterAssemblyStyle.cs" />
|
||||
<Compile Include="Formatting.cs" />
|
||||
<Compile Include="IJsonLineInfo.cs" />
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<Compile Include="DateParseHandling.cs" />
|
||||
<Compile Include="DateTimeZoneHandling.cs" />
|
||||
<Compile Include="FloatFormatHandling.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="FormatterAssemblyStyle.cs" />
|
||||
<Compile Include="DefaultValueHandling.cs" />
|
||||
<Compile Include="Formatting.cs" />
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
<Compile Include="Converters\StringEnumConverter.cs" />
|
||||
<Compile Include="Converters\VersionConverter.cs" />
|
||||
<Compile Include="Converters\XmlNodeConverter.cs" />
|
||||
<Compile Include="FloatParseHandling.cs" />
|
||||
<Compile Include="DateFormatHandling.cs" />
|
||||
<Compile Include="DateParseHandling.cs" />
|
||||
<Compile Include="DateTimeZoneHandling.cs" />
|
||||
|
||||
@@ -90,6 +90,6 @@ using System.Security;
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.0.1.15924")]
|
||||
[assembly: AssemblyFileVersion("5.0.1.15926")]
|
||||
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
@@ -33,7 +33,9 @@ using System.Dynamic;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
#if !(PORTABLE || NET35 || NET20 || SILVERLIGHT)
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -665,8 +667,10 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
return Enum.ToObject(contract.NonNullableUnderlyingType, value);
|
||||
}
|
||||
|
||||
#if !(PORTABLE || NET35 || NET20 || SILVERLIGHT)
|
||||
if (value is BigInteger)
|
||||
return ConvertUtils.FromBigInteger((BigInteger)value, targetType);
|
||||
#endif
|
||||
|
||||
return Convert.ChangeType(value, contract.NonNullableUnderlyingType, culture);
|
||||
}
|
||||
|
||||
@@ -162,6 +162,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
set { _serializer.FloatFormatHandling = value; }
|
||||
}
|
||||
|
||||
public override FloatParseHandling FloatParseHandling
|
||||
{
|
||||
get { return _serializer.FloatParseHandling; }
|
||||
set { _serializer.FloatParseHandling = value; }
|
||||
}
|
||||
|
||||
public override StringEscapeHandling StringEscapeHandling
|
||||
{
|
||||
get { return _serializer.StringEscapeHandling; }
|
||||
|
||||
Reference in New Issue
Block a user