-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSerializeUnindentedJson.cs
47 lines (38 loc) · 1.25 KB
/
SerializeUnindentedJson.cs
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
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2007 James Newton-King. All rights reserved.
// Use of this source code is governed by The MIT License,
// as found in the license.md file.
public class SerializeUnindentedJson : TestFixtureBase
{
#region SerializeUnindentedJsonTypes
public class Account
{
public string Email { get; set; }
public bool Active { get; set; }
public DateTime CreatedDate { get; set; }
public IList<string> Roles { get; set; }
}
#endregion
[Fact]
public void Example()
{
#region SerializeUnindentedJsonUsage
var account = new Account
{
Email = "james@example.com",
Active = true,
CreatedDate = new(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc),
Roles =
[
"User",
"Admin"
]
};
var json = JsonConvert.SerializeObject(account);
// {"Email":"james@example.com","Active":true,"CreatedDate":"2013-01-20T00:00:00Z","Roles":["User","Admin"]}
Console.WriteLine(json);
#endregion
Assert.Equal(
"""{"Email":"james@example.com","Active":true,"CreatedDate":"2013-01-20T00:00:00Z","Roles":["User","Admin"]}""",
json);
}
}