Пример #1
0
        public static void Regression38565_Deserialize_IgnoreNullValues()
        {
            var json = "{\"Test\":\"value1\",\"Child\":{}}";
            Regression38565_Parent actual = JsonSerializer.Deserialize <Regression38565_Parent>(json);

            Assert.Equal("value1", actual.Test);
            Assert.Null(actual.Dict);
            Assert.NotNull(actual.Child);
            Assert.Null(actual.Child.Dict);
            Assert.Null(actual.Child.Test);
        }
Пример #2
0
        public static void Regression38565_Serialize()
        {
            var value = new Regression38565_Parent()
            {
                Test  = "value1",
                Child = new Regression38565_Child()
            };

            var actual = JsonSerializer.Serialize(value);

            Assert.Equal("{\"Test\":\"value1\",\"Dict\":null,\"Child\":{\"Test\":null,\"Dict\":null}}", actual);
        }
Пример #3
0
        public static void Regression38565_Serialize_IgnoreNullValues()
        {
            var value = new Regression38565_Parent()
            {
                Test  = "value1",
                Child = new Regression38565_Child()
            };

            var actual = JsonSerializer.Serialize(value, new JsonSerializerOptions {
                IgnoreNullValues = true
            });

            Assert.Equal("{\"Test\":\"value1\",\"Child\":{}}", actual);
        }