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

Commit d4f0635

Browse files
committed
Add JsConfig<T>.IncludeDefaultValue example with KeyValue Pair
1 parent 328ce9e commit d4f0635

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,12 @@ public void Can_deserialize_json_with_underscores()
234234
}
235235
}
236236

237-
public class CustomSerailizerValueTypeTests
237+
public class CustomSerailizerValueTypeTests
238238
{
239-
[Ignore("Need to clear static element caches"), Test]
239+
[Ignore("Needs to clear dirty static element caches from other tests"), Test]
240240
public void Can_serialize_custom_doubles()
241241
{
242+
JsConfig<double>.IncludeDefaultValue = true;
242243
JsConfig<double>.RawSerializeFn = d =>
243244
double.IsPositiveInfinity(d) ?
244245
"\"+Inf\""
@@ -251,6 +252,11 @@ public void Can_serialize_custom_doubles()
251252
var doubles = new[] { 0.0, 1.0, double.NegativeInfinity, double.NaN, double.PositiveInfinity };
252253

253254
Assert.That(doubles.ToJson(), Is.EqualTo("[0,1,\"-Inf\",\"NaN\",\"+Inf\"]"));
255+
256+
Assert.That(new KeyValuePair<double, double>(0, 1).ToJson(),
257+
Is.EqualTo("{\"Key\":0,\"Value\":1}"));
258+
259+
JsConfig.Reset();
254260
}
255261

256262
public class Model
@@ -261,13 +267,16 @@ public class Model
261267
[Test]
262268
public void Can_serialize_custom_ints()
263269
{
264-
JsConfig<int>.IncludeDefaultValue = true;
270+
//JsConfig<int>.IncludeDefaultValue = true;
265271
JsConfig<int>.RawSerializeFn = i =>
266272
i == 0 ? "-1" : i.ToString();
267273

268274
var dto = new Model { Int = 0 };
269275

270-
Assert.That(dto.ToJson(), Is.EqualTo("{\"Int\":-1}"));
276+
using (JsConfig.With(includeNullValues: true))
277+
{
278+
Assert.That(dto.ToJson(), Is.EqualTo("{\"Int\":-1}"));
279+
}
271280

272281
JsConfig.Reset();
273282
}

0 commit comments

Comments
 (0)