Skip to content

Commit 08213e7

Browse files
authored
perf: Change JsonSerializerOptions instance to static (#9163)
1 parent 0e6c556 commit 08213e7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Docfx.Build.SchemaDriven/Models/DocumentSchema.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ namespace Docfx.Build.SchemaDriven;
1111

1212
public class DocumentSchema : BaseSchema
1313
{
14+
// JsonSerializerOptions should be reused.
15+
// https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/configure-options#reuse-jsonserializeroptions-instances
16+
private static readonly JsonSerializerOptions SerializerOptions = new()
17+
{
18+
AllowTrailingCommas = true,
19+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
20+
Converters = {
21+
new JsonStringEnumConverter()
22+
},
23+
};
24+
1425
public string Metadata { get; set; }
1526

1627
public JsonPointer MetadataReference { get; private set; }
@@ -30,14 +41,7 @@ public static DocumentSchema Load(string content, string title)
3041
{
3142
schema = JsonSerializer.Deserialize<DocumentSchema>(
3243
content,
33-
new JsonSerializerOptions()
34-
{
35-
AllowTrailingCommas = true,
36-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
37-
Converters = {
38-
new JsonStringEnumConverter()
39-
}
40-
});
44+
SerializerOptions);
4145
}
4246
catch (Exception e)
4347
{

0 commit comments

Comments
 (0)