-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonOptions.cs
More file actions
33 lines (29 loc) · 1.05 KB
/
Copy pathJsonOptions.cs
File metadata and controls
33 lines (29 loc) · 1.05 KB
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
using System.Text.Json;
using System.Text.Json.Serialization;
namespace JSONstat.IO;
/// <summary>
/// Shared <see cref="JsonSerializerOptions"/> for the JSON-stat format.
/// </summary>
public static class JsonOptions
{
static JsonOptions()
{
Default = Build();
}
/// <summary>The default, cached options instance (safe to reuse).</summary>
public static JsonSerializerOptions Default { get; }
/// <summary>Builds a fresh options instance configured for JSON-stat v2.0.</summary>
public static JsonSerializerOptions Build()
{
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = false,
};
options.Converters.Add(new ResponseConverter());
options.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
// ValueCollection and StatusCollection carry their own [JsonConverter].
return options;
}
}