public void Serialize_skips_null_values_by_default() { var o = new NullValueTester { Name = "Brandon", Type = "Programmer", SampleKey = 12, Nothing = (string)null }; var s = JsonSerializer.SerializeToString(o); Assert.That(s, Is.EqualTo("{\"Name\":\"Brandon\",\"Type\":\"Programmer\",\"SampleKey\":12}")); }
public void Serialize_can_include_null_values() { var o = new NullValueTester { Name = "Brandon", Type = "Programmer", SampleKey = 12, Nothing = null }; JsConfig.IncludeNullValues = true; var s = JsonSerializer.SerializeToString(o); JsConfig.IncludeNullValues = false; Assert.That(s, Is.EqualTo("{\"Name\":\"Brandon\",\"Type\":\"Programmer\",\"SampleKey\":12,\"Nothing\":null}")); }
public void Serialize_can_include_null_values() { var o = new NullValueTester { Name = "Brandon", Type = "Programmer", SampleKey = 12, Nothing = null, NullClass = null, NullableDateTime = null, }; JsConfig.IncludeNullValues = true; var s = JsonSerializer.SerializeToString(o); JsConfig.Reset(); Assert.That(s, Is.EqualTo("{\"Name\":\"Brandon\",\"Type\":\"Programmer\",\"SampleKey\":12,\"Nothing\":null,\"NullClass\":null,\"NullableDateTime\":null}")); }