Ejemplo n.º 1
0
        public void Test_structs_with_double_quotes()
        {
            var dto = new Foo {
                Content1 = "My \"quoted\" content", Name = "My \"quoted\" name"
            };

            JsConfig <Text> .SerializeFn   = text => text.ToString();
            JsConfig <Text> .DeSerializeFn = v => new Text(v);
            JsConfig <Foo> .Refresh();

            var json = JsonSerializer.SerializeToString(dto, dto.GetType());

            Assert.That(json, Is.EqualTo("{\"Name\":\"My \\\"quoted\\\" name\",\"Content1\":\"My \\\"quoted\\\" content\"}"));

            var foo = JsonSerializer.DeserializeFromString <Foo>(json);

            Assert.That(foo.Name, Is.EqualTo(dto.Name));
            Assert.That(foo.Content1, Is.EqualTo(dto.Content1));
        }