Skip to content

Instantly share code, notes, and snippets.

@jfbueno
Created May 20, 2016 13:05
Show Gist options
  • Save jfbueno/6bdb2ed3fa403140a7c4d01681f6bbe2 to your computer and use it in GitHub Desktop.
Save jfbueno/6bdb2ed3fa403140a7c4d01681f6bbe2 to your computer and use it in GitHub Desktop.
public class CamelCaseControllerConfigAttribute : 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 CamelCasePropertyNamesContractResolver() }
};
controllerSettings.Formatters.Add(formatter);
}
}
[CamelCaseControllerConfig]
public dynamic Get()
{
return new
{
Nome = "Jeferson",
Sobrenome = "Bueno",
Idade = 2000
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment