Description
When serializing object of KeyValuePair the serializer doesn't take JsonNamingPolicy.CamelCase option into consideration. The following example code tries to depict the situation.
class Program
{
static void Main(string[] args)
{
var opt = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
var kvp = new KeyValuePair<string, string>("one", "1");
Console.WriteLine("Without Option: " + JsonSerializer.Serialize(kvp));
Console.WriteLine("With Option: " + JsonSerializer.Serialize(kvp, opt));
}
}
Result:
Without Option: {"Key":"one","Value":"1"}
With Option: {"Key":"one","Value":"1"}
Expected Result:
Without Option: {"Key":"one","Value":"1"}
With Option: {"key":"one","value":"1"}
Configuration
.NET Version: Core 3.1
OS: Windows 10 20H2
Architecture: x64