There is a bug in ServiceApi when using System.Text.Json as default serializer with camelCase as formatting. Using Newtonsoft works as expected.
After some digging I the cause. JsonSerializerOptions in method GetSerializerOptions is not instanciated correctly while using camelCase. It is using the default constructor which will use PascalCase as default.
The options should set camelCase as PropertyNamingPolicy or use another constructor that takes default values.
private static object GetOptions()
{
if (ServiceProviderExtensions.TryGetExistingInstance<IActionResultExecutor<JsonResult>>(ServiceLocator.Current, out var instance) && instance.GetType().FullName.Contains("Newtonsoft"))
{
if (ServiceProviderExtensions.GetInstance<ServiceApiOptions>(ServiceLocator.Current).JsonPropertyNaming.Value == JsonPropertyNaming.PascalCase)
{
return new JsonSerializerSettings();
}
return new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy()
}
};
}
return GetSerializerOptions();
}
private static JsonSerializerOptions GetSerializerOptions()
{
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions();
if (ServiceProviderExtensions.GetInstance<ServiceApiOptions>(ServiceLocator.Current).JsonPropertyNaming.Value == JsonPropertyNaming.PascalCase)
{
jsonSerializerOptions.PropertyNamingPolicy = null;
}
return jsonSerializerOptions;
}
There is a bug in ServiceApi when using System.Text.Json as default serializer with camelCase as formatting. Using Newtonsoft works as expected.
After some digging I the cause. JsonSerializerOptions in method GetSerializerOptions is not instanciated correctly while using camelCase. It is using the default constructor which will use PascalCase as default.
The options should set camelCase as PropertyNamingPolicy or use another constructor that takes default values.