Beispiel #1
0
        public void Deserialize_GivenModelWithDefaultArrayPropertyOfNullAndNoArrayPropertyInJSON_DeserializesArrayPropertyAsEmpty(bool ignoreNullValues)
        {
            // Arrange
            const string          json = "{ }";
            JsonSerializerOptions jsonSerializerOptions = CreateOptions(ignoreNullValues);

            // Act
            DefaultsToNotNullModelTestClass result = JsonSerializer.Deserialize <DefaultsToNotNullModelTestClass>(json, jsonSerializerOptions);

            // Assert
            Assert.AreEqual(result.ArrayProperty.Length, 0);
        }
Beispiel #2
0
        public void Deserialize_GivenModelWithDefaultArrayPropertyOfNotNullAndArrayPropertyInJSON_DeserializesArrayProperty(bool ignoreNullValues)
        {
            // Arrange
            const string value1 = "value-1";
            const string value2 = "value-2";

            string json = $@"{{ ""ArrayProperty"": [""{value1}"", ""{value2}""] }}";
            JsonSerializerOptions jsonSerializerOptions = CreateOptions(ignoreNullValues);

            // Act
            DefaultsToNotNullModelTestClass result = JsonSerializer.Deserialize <DefaultsToNotNullModelTestClass>(json, jsonSerializerOptions);

            // Assert
            Assert.IsNotNull(result.ArrayProperty);
            Assert.AreEqual(result.ArrayProperty.Length, 2);
            Assert.AreEqual(result.ArrayProperty[0], value1);
            Assert.AreEqual(result.ArrayProperty[1], value2);
        }