In the creation of our new MVC Web API-based service, we want to focus on XML to begin with and add JSON functionality later as an enhancement, using the full release with nativ
All you have to do is to remove JSON media formatters.
// Identify JSON formatters in global config.
var jsonMediaTypeFormatters = GlobalConfiguration.Configuration.Formatters
.Where(x => x.SupportedMediaTypes
.Any(y => y.MediaType.Equals("application/json", StringComparison.InvariantCultureIgnoreCase)))
.ToList();
// Remove formatters from global config.
foreach (var formatter in jsonMediaTypeFormatters)
{
GlobalConfiguration.Configuration.Formatters.Remove(formatter);
}
There's an even shorter option, because there can be only one Json formatter and the MediaTypeFormatterCollection exposes it as a property. Available since Web API 2 (maybe also in v1, not sure).
Formatters.Remove(controllerSettings.Formatters.JsonFormatter)