title: Web API change JSON parser
body: <p>I am trying to change the JSON parser in my web API project.</p>
  
  <p>I have followed the following tutorials:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/custom-formatters?view=aspnetcore-2.2" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/custom-formatters?view=aspnetcore-2.2</a></p>
  
  <p><a href="https://www.youtube.com/watch?v=tNzgXjqqIjI" rel="nofollow noreferrer">https://www.youtube.com/watch?v=tNzgXjqqIjI</a></p>
  
  <p><a href="https://weblog.west-wind.com/posts/2012/Mar/09/Using-an-alternate-JSON-Serializer-in-ASPNET-Web-API" rel="nofollow noreferrer">https://weblog.west-wind.com/posts/2012/Mar/09/Using-an-alternate-JSON-Serializer-in-ASPNET-Web-API</a></p>
  
  <p>I now have the following code:</p>
  
  <pre><code>public class MyJsonFormatter : MediaTypeFormatter
      {
          public MyJsonFormatter()
          {
              base.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
          }
  
          public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)
          {
              return null;
          }
  
          public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
          {
              return null;
          }
  
          public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
          {
              base.SetDefaultContentHeaders(type, headers, mediaType);
          }
  
          public override bool CanReadType(Type type)
          {
              return true;
          }
  
          public override bool CanWriteType(Type type)
          {
              return true;
          }
  
          public override MediaTypeFormatter GetPerRequestFormatterInstance(Type type, HttpRequestMessage request, MediaTypeHeaderValue mediaType)
          {
              return base.GetPerRequestFormatterInstance(type, request, mediaType);
          }
  
          public override Task&lt;object&gt; ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
          {
              return null;
          }
  
          public override Task&lt;object&gt; ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
          {
              return null;
          }
  
          public override IRequiredMemberSelector RequiredMemberSelector { get =&gt; base.RequiredMemberSelector; set =&gt; base.RequiredMemberSelector = value; }
      }   
  
  
  
  public static void Register(HttpConfiguration config)
  {
      ///Other stuff...
      GlobalConfiguration.Configuration.Formatters.Clear();
      GlobalConfiguration.Configuration.Formatters.Insert(0, new MyJsonFormatter());          
  }
  </code></pre>
  
  <p>My issue is that whatever I do, JSON gets parsed and it seems to ignore my code - I can throw exceptions in the read or write methods and nothing will happen, break points do not get hit etc.</p>
  
  <p>I know this formatter is being added as only the content types in my class are visible and if I set <code>CanReadType</code> to return false then nothing gets parsed.</p>
  
  <p>My question is, how can I make the code execute my overrides?</p>