Skip to content

Instantly share code, notes, and snippets.

@hansmaad
Forked from mauricedb/gist:5356933
Last active August 29, 2015 14:00
Show Gist options
  • Save hansmaad/11254836 to your computer and use it in GitHub Desktop.
Save hansmaad/11254836 to your computer and use it in GitHub Desktop.
WebApiConfig JSON configuration
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Configure Json Serializer to serialize enums as string instead of numbers
// Use camel case for property names
var jsonSetting = new JsonSerializerSettings();
jsonSetting.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
jsonSetting.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.SerializerSettings = jsonSetting;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment