title: ASP.NET Core - How to know deserialization has failed through middleware
body: <p>Let's assume this code:</p>
  
  <pre><code>public class Test
  {
      public DateTime     Date        { get; set; }
      public string       Title       { get; set; }
  }
  
  [HttpPut, Route("test")]
  public IActionResult test([FromBody]Test Data)
  {
      ....
  }
  </code></pre>
  
  <p>If the user is providing invalid json in the body, <em>Data</em> will be null.</p>
  
  <p>Is there a way to catch this before the code is executed so I don't have to test for null on every API method?</p>
  
  <p>I was thinking it may be doable as a middleware, but I have no experience with that, so I am not sure.</p>