Attribute for WebApi controllers that camel cases object property names when serialized to Json

This commit is contained in:
Rusty Swayne
2014-06-09 05:39:14 -07:00
parent e5dea8e4be
commit 632cd221d9

View File

@@ -0,0 +1,17 @@
using System;
using System.Web.Http.Controllers;
using Newtonsoft.Json.Serialization;
namespace Umbraco.Web.WebApi
{
/// <summary>
/// Applying this attribute to any webapi controller will ensure that it only contains one json formatter compatible with the angular json vulnerability prevention.
/// </summary>
public class JsonCamelCaseFormatter : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
controllerSettings.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
}
}