-Change FloatFormatHandling.Zero to DefaultValue
-Documentation
This commit is contained in:
@@ -433,7 +433,7 @@ namespace Newtonsoft.Json.Tests
|
||||
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
|
||||
{
|
||||
jsonWriter.Formatting = Formatting.Indented;
|
||||
jsonWriter.FloatFormatHandling = FloatFormatHandling.Zero;
|
||||
jsonWriter.FloatFormatHandling = FloatFormatHandling.DefaultValue;
|
||||
|
||||
jsonWriter.WriteStartArray();
|
||||
jsonWriter.WriteValue(double.NaN);
|
||||
@@ -442,6 +442,12 @@ namespace Newtonsoft.Json.Tests
|
||||
jsonWriter.WriteValue(float.NaN);
|
||||
jsonWriter.WriteValue(float.PositiveInfinity);
|
||||
jsonWriter.WriteValue(float.NegativeInfinity);
|
||||
jsonWriter.WriteValue((double?)double.NaN);
|
||||
jsonWriter.WriteValue((double?)double.PositiveInfinity);
|
||||
jsonWriter.WriteValue((double?)double.NegativeInfinity);
|
||||
jsonWriter.WriteValue((float?)float.NaN);
|
||||
jsonWriter.WriteValue((float?)float.PositiveInfinity);
|
||||
jsonWriter.WriteValue((float?)float.NegativeInfinity);
|
||||
jsonWriter.WriteEndArray();
|
||||
|
||||
jsonWriter.Flush();
|
||||
@@ -453,7 +459,13 @@ namespace Newtonsoft.Json.Tests
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
0.0,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]";
|
||||
string result = sb.ToString();
|
||||
|
||||
|
||||
@@ -76,5 +76,5 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("4.5.0.0")]
|
||||
#if !PocketPC
|
||||
[assembly: AssemblyFileVersion("4.5.11.15802")]
|
||||
[assembly: AssemblyFileVersion("4.5.11.15809")]
|
||||
#endif
|
||||
|
||||
@@ -7124,6 +7124,43 @@ Parameter name: value",
|
||||
Assert.AreEqual("07/19/2012 14:30:00 +09:30", dateTimeOffset.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public class NullableFloats
|
||||
{
|
||||
public object Object { get; set; }
|
||||
public float Float { get; set; }
|
||||
public double Double { get; set; }
|
||||
public float? NullableFloat { get; set; }
|
||||
public double? NullableDouble { get; set; }
|
||||
public object ObjectNull { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullableFloatingPoint()
|
||||
{
|
||||
NullableFloats floats = new NullableFloats
|
||||
{
|
||||
Object = double.NaN,
|
||||
ObjectNull = null,
|
||||
Float = float.NaN,
|
||||
NullableDouble = double.NaN,
|
||||
NullableFloat = null
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(floats, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
FloatFormatHandling = FloatFormatHandling.DefaultValue
|
||||
});
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Object"": 0.0,
|
||||
""Float"": 0.0,
|
||||
""Double"": 0.0,
|
||||
""NullableFloat"": null,
|
||||
""NullableDouble"": null,
|
||||
""ObjectNull"": null
|
||||
}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateFormatString()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user