I have camelCase by default in my Web API, but I need disable this setting in a specific controller (or in specific http action). This is possible?
Asked
Active
Viewed 1,609 times
1 Answers
4
I resolved this with this answer: https://stackoverflow.com/a/19959579/3621839
I changed to do the reverse, only:
using System;
using System.Linq;
using System.Web.Http.Controllers;
using System.Net.Http.Formatting;
using Newtonsoft.Json.Serialization;
public class DisableCamelCaseSerialization : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
var formatter = controllerSettings.Formatters.OfType<JsonMediaTypeFormatter>().Single();
controllerSettings.Formatters.Remove(formatter);
formatter = new JsonMediaTypeFormatter
{
SerializerSettings = { ContractResolver = new DefaultContractResolver() }
};
controllerSettings.Formatters.Add(formatter);
}
}