Skip to content

Commit 2807291

Browse files
committed
feat(serialization): add preconfigured JsonSerializerOptions for Web API
- Introduces new `JavascriptWebApi` and `Payload` options for enhanced serialization in Web API requests. - Ensures consistent property naming and case sensitivity by utilizing appropriate `JsonStringEnumConverter` settings. - Provides a dedicated option for payload serialization with case insensitivity and improved defaults.
1 parent abccb05 commit 2807291

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/ES.FX.Additions.System.Text.Json/Serialization/JsonSerializerOptionsExtended.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,39 @@ public static class JsonSerializerOptionsExtended
2020
/// <remarks>
2121
/// The options are initialized with the <see cref="JsonSerializerDefaults.Web" /> settings and include a
2222
/// <see cref="JsonStringEnumConverter" /> that uses the property naming policy defined by
23-
/// <see cref="JsonSerializerOptions.Web" />. The converter is configured for case-sensitive enum conversion.
23+
/// <see cref="JsonSerializerOptions.Default" />. The converter is configured for case-sensitive enum conversion.
2424
/// </remarks>
2525
public static JsonSerializerOptions WebApi { get; } = new(JsonSerializerDefaults.Web)
26+
{
27+
Converters = { new JsonStringEnumConverter(JsonSerializerOptions.Default.PropertyNamingPolicy, false) }
28+
};
29+
30+
31+
/// <summary>
32+
/// Gets the <see cref="JsonSerializerOptions" /> preconfigured for Web API usage.
33+
/// </summary>
34+
/// <remarks>
35+
/// The options are initialized with the <see cref="JsonSerializerDefaults.Web" /> settings and include a
36+
/// <see cref="JsonStringEnumConverter" /> that uses the property naming policy defined by
37+
/// <see cref="JsonSerializerOptions.Web" />. The converter is configured for case-sensitive enum conversion.
38+
/// </remarks>
39+
public static JsonSerializerOptions JavascriptWebApi { get; } = new(JsonSerializerDefaults.Web)
2640
{
2741
Converters = { new JsonStringEnumConverter(JsonSerializerOptions.Web.PropertyNamingPolicy, false) }
2842
};
43+
44+
45+
/// <summary>
46+
/// Gets the <see cref="JsonSerializerOptions" /> preconfigured for payload serialization
47+
/// </summary>
48+
/// <remarks>
49+
/// The options are initialized with the <see cref="JsonSerializerDefaults.Default" /> settings and include a
50+
/// <see cref="JsonStringEnumConverter" /> that uses the property naming policy defined by
51+
/// <see cref="JsonSerializerOptions.Default" />. The converter is configured for case-sensitive enum conversion.
52+
/// </remarks>
53+
public static JsonSerializerOptions Payload { get; } = new(JsonSerializerDefaults.General)
54+
{
55+
PropertyNameCaseInsensitive = true,
56+
Converters = { new JsonStringEnumConverter(JsonSerializerOptions.Default.PropertyNamingPolicy) }
57+
};
2958
}

0 commit comments

Comments
 (0)