Skip to content

Instantly share code, notes, and snippets.

@ShawInnes
Last active January 3, 2016 15:39
Show Gist options
  • Save ShawInnes/8484739 to your computer and use it in GitHub Desktop.
Save ShawInnes/8484739 to your computer and use it in GitHub Desktop.
WebAPI Config with JSON
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
config.EnsureInitialized();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment