The Json formatter is only looking for an "application/json" or similar accept header and so is skipped over, triggering the Xml formatter when it sees the "application/xml" accept header.
You could clear the SupportedMediaTypes from the XmlFormatter (in Application_Start):
But then no one would get Xml. So, easy peasy, just add "text/html" to the JsonFormatters supported media types and you get Json in the browser, but if someone really wants "application/xml" they can get that too by only requesting the appropriate type.
You can doublecheck in the debugger that Json is the first formatter, but this worked for me:
GlobalConfiguration.Configuration.Formatters .SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
Why not just GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue("text/html"));?ReplyDelete
This protects you in case the order of the formatters changes at some point in the future.