Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit dd9449b

Browse files
committed
Add Can_serialize_custom_doubles test
1 parent 06045c0 commit dd9449b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/ServiceStack.Text.Tests/JsonTests/CustomSerializerTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,22 @@ public void Can_deserialize_json_with_underscores()
232232
dto.PrintDump();
233233
}
234234
}
235+
236+
[Test]
237+
public void Can_serialize_custom_doubles()
238+
{
239+
JsConfig<double>.RawSerializeFn = d =>
240+
double.IsPositiveInfinity(d) ?
241+
"\"+Inf\""
242+
: double.IsNegativeInfinity(d) ?
243+
"\"-Inf\""
244+
: double.IsNaN(d) ?
245+
"\"NaN\""
246+
: d.ToString();
247+
248+
var doubles = new[] { 0.0, 1.0, double.NegativeInfinity, double.NaN, double.PositiveInfinity };
249+
250+
Assert.That(doubles.ToJson(), Is.EqualTo("[0,1,\"-Inf\",\"NaN\",\"+Inf\"]"));
251+
}
235252
}
236253
}

0 commit comments

Comments
 (0)