コード例 #1
0
 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}"));
 }
コード例 #2
0
        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}"));
        }
コード例 #3
0
        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}"));
        }
コード例 #4
0
        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}"));
        }