public async Task ObjectZeroLengthProperty()
        {
            // Default

            ClassWithZeroLengthProperty <int> rootValue = await RoundTripZeroLengthProperty(new ClassWithZeroLengthProperty <int>(), 10);

            Assert.Equal(10, rootValue.ZeroLengthProperty);

            ClassWithZeroLengthProperty <Employee> rootObject = await RoundTripZeroLengthProperty(new ClassWithZeroLengthProperty <Employee>(), new Employee { Name = "Test" });

            Assert.Equal("Test", rootObject.ZeroLengthProperty.Name);

            ClassWithZeroLengthProperty <List <int> > rootArray = await RoundTripZeroLengthProperty(new ClassWithZeroLengthProperty <List <int> >(), new List <int>());

            Assert.Equal(0, rootArray.ZeroLengthProperty.Count);

            // Preserve

            ClassWithZeroLengthProperty <int> rootValue2 = await RoundTripZeroLengthProperty(new ClassWithZeroLengthProperty <int>(), 10, s_deserializerOptionsPreserve);

            Assert.Equal(10, rootValue2.ZeroLengthProperty);

            ClassWithZeroLengthProperty <Employee> rootObject2 = await RoundTripZeroLengthProperty(new ClassWithZeroLengthProperty <Employee>(), new Employee { Name = "Test" }, s_deserializerOptionsPreserve);

            Assert.Equal("Test", rootObject2.ZeroLengthProperty.Name);

            ClassWithZeroLengthProperty <List <int> > rootArray2 = await RoundTripZeroLengthProperty(new ClassWithZeroLengthProperty <List <int> >(), new List <int>(), s_deserializerOptionsPreserve);

            Assert.Equal(0, rootArray2.ZeroLengthProperty.Count);
        }
Esempio n. 2
0
        public static void ObjectPropertyLengthZero()
        {
            string json = @"{
                """": 1
            }";

            ClassWithZeroLengthProperty <int> root = JsonSerializer.Deserialize <ClassWithZeroLengthProperty <int> >(json, s_deserializerOptionsPreserve);

            Assert.Equal(1, root.ZeroLengthProperty);
        }
        private async Task <ClassWithZeroLengthProperty <TValue> > RoundTripZeroLengthProperty <TValue>(ClassWithZeroLengthProperty <TValue> obj, TValue value, JsonSerializerOptions opts = null)
        {
            obj.ZeroLengthProperty = value;
            string json = await JsonSerializerWrapperForString.SerializeWrapper(obj, opts);

            Assert.Contains("\"\":", json);

            return(await JsonSerializerWrapperForString.DeserializeWrapper <ClassWithZeroLengthProperty <TValue> >(json, opts));
        }
Esempio n. 4
0
        private static ClassWithZeroLengthProperty <TValue> RoundTripZeroLengthProperty <TValue>(ClassWithZeroLengthProperty <TValue> obj, TValue value, JsonSerializerOptions opts = null)
        {
            obj.ZeroLengthProperty = value;
            string json = JsonSerializer.Serialize(obj, opts);

            Assert.Contains("\"\":", json);

            return(JsonSerializer.Deserialize <ClassWithZeroLengthProperty <TValue> >(json, opts));
        }