I want camel cased JSON on all controller results expect for one specific controller that returns a Dictionary
I tried this
public class PascalCaseConfigAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings config,
HttpControllerDescriptor controllerDescriptor)
{
var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().Single();
jsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver();
}
}
But that changes the global config so after any controller has been called with that attribute we will be back att Pascal case.
How can I fix so taht the default is camel case and explicit fix Paascal case for a certain controller?
edit: This works but feels a bit backward
public class PascalCaseConfigAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings config,
HttpControllerDescriptor controllerDescriptor)
{
var formatter = config.Formatters.OfType<JsonMediaTypeFormatter>().Single();
config.Formatters.Remove(formatter);
formatter = new JsonMediaTypeFormatter();
formatter.SerializerSettings.ContractResolver = new DefaultContractResolver();
config.Formatters.Add(formatter);
}
}