From 632cd221d9318f43acaaab298cd2aedeffde57d2 Mon Sep 17 00:00:00 2001 From: Rusty Swayne Date: Mon, 9 Jun 2014 05:39:14 -0700 Subject: [PATCH] Attribute for WebApi controllers that camel cases object property names when serialized to Json --- .../WebApi/JsonCamelCaseFormatter.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/Umbraco.Web/WebApi/JsonCamelCaseFormatter.cs diff --git a/src/Umbraco.Web/WebApi/JsonCamelCaseFormatter.cs b/src/Umbraco.Web/WebApi/JsonCamelCaseFormatter.cs new file mode 100644 index 0000000000..67adea187f --- /dev/null +++ b/src/Umbraco.Web/WebApi/JsonCamelCaseFormatter.cs @@ -0,0 +1,17 @@ +using System; +using System.Web.Http.Controllers; +using Newtonsoft.Json.Serialization; + +namespace Umbraco.Web.WebApi +{ + /// + /// Applying this attribute to any webapi controller will ensure that it only contains one json formatter compatible with the angular json vulnerability prevention. + /// + public class JsonCamelCaseFormatter : Attribute, IControllerConfiguration + { + public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) + { + controllerSettings.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + } + } +} \ No newline at end of file