Ejemplo n.º 1
0
        public async Task BoxedStructReferencePreservation_NestedStructObject()
        {
            IBoxedStructWithObjectProperty value = new StructWithObjectProperty();

            value.Property = new object[] { value };

            string json = await JsonSerializerWrapperForString.SerializeWrapper(value, new JsonSerializerOptions { ReferenceHandler = ReferenceHandler.Preserve });

            Assert.Equal(@"{""$id"":""1"",""Property"":[{""$ref"":""1""}]}", json);
        }
Ejemplo n.º 2
0
        public async Task BoxedStructReferencePreservation_SiblingStructObjects()
        {
            object box = new StructWithObjectProperty {
                Property = 42
            };
            var array = new object[] { box, box };

            string json = await JsonSerializerWrapperForString.SerializeWrapper(array, s_serializerOptionsPreserve);

            Assert.Equal(@"[{""$id"":""1"",""Property"":42},{""$ref"":""1""}]", json);
        }
Ejemplo n.º 3
0
        public static void BoxedStructReferencePreservation_SiblingStructObjects()
        {
            object box = new StructWithObjectProperty {
                Property = 42
            };
            var array = new object[] { box, box };

            string json = JsonSerializer.Serialize(array, s_serializerOptionsPreserve);

            Assert.Equal(@"[{""$id"":""1"",""Property"":42},{""$ref"":""1""}]", json);
        }
Ejemplo n.º 4
0
        public static void BoxedStructReferencePreservation_NestedStructObject()
        {
            IBoxedStructWithObjectProperty value = new StructWithObjectProperty();

            value.Property = new object[] { value };

            string json = JsonSerializer.Serialize(value, new JsonSerializerOptions {
                ReferenceHandler = ReferenceHandler.Preserve
            });

            Assert.Equal(@"{""$id"":""1"",""Property"":[{""$ref"":""1""}]}", json);
        }