~euantorano/system.text.json-object-serialization

ref: 361368ff9bdcb75072c0895dfcdbc2317bf3c744 system.text.json-object-serialization/JsonEncodeTest/BaseClass.cs -rw-r--r-- 884 bytes
361368ffEuan Torano Initial commit 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Text.Json;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace JsonEncodeTest
{
    public class BaseClass
    {
        [JsonPropertyName("int_val")]
        [JsonProperty("int_val")]
        public int IntVal { get; set; }

        public string ToJsonSystemText()
        {
            return JsonSerializer.Serialize(this, GetType(), new JsonSerializerOptions()
            {
                WriteIndented = false
            });
        }

        public string ToJsonSystemTextBroken()
        {
            return JsonSerializer.Serialize(this, new JsonSerializerOptions()
            {
                WriteIndented = false
            });
        }

        public string ToJsonJsonNet()
        {
            return JsonConvert.SerializeObject(this, Formatting.None);
        }
    }
}