'Unable to remove XML formatter and configure JSON formatter

I am trying to remove the XML formatter and configure JSON formatter only for my web API, but its not working, the response data is still being displayed in XML format. Here's my code in Startup.cs. I have followed the steps from this site: https://developer.okta.com/blog/2019/03/13/build-rest-api-with-aspnet-web-`api

    using System.Net.Http.Formatting;
    using System.Web.Http;
    using Newtonsoft.Json.Serialization;
    using Owin;

    namespace AspNetWebApiRest
    {
      public class Startup
       {
        public void Configuration(IAppBuilder app)
         {
        var config = new HttpConfiguration();

        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Formatters.Remove(config.Formatters.XmlFormatter);
        JsonMediaTypeFormatter jsonFormatter = config.Formatters.JsonFormatter;
        config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new 
        CamelCasePropertyNamesContractResolver();
        config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = 
         Newtonsoft.Json.DateTimeZoneHandling.Utc;
        app.UseWebApi(config);
    }
}

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source