title: How do I configure validation error details return content-type as application/problem+json instead of application/json?
body: <p>Currently when the validation type failed (here I am using data annotation ValidationAttribute), its content-type is <code>application/json</code>.</p>
  <p><a href="https://i.stack.imgur.com/xZcO0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xZcO0.png" alt="enter image description here" /></a></p>
  <p>How do I configure it to return its content-type as <code>application/problem+json</code> while maintaining the error details?</p>
  <p>Here is my controller in NET 6 Web Api project.</p>
  <pre><code>[Route(&quot;api/[controller]&quot;)]
  [ApiController]
  public class AccountController : ControllerBase
  {
      private readonly IAccountService _accountService;
  
      /// &lt;summary&gt;
      /// 
      /// &lt;/summary&gt;
      /// &lt;param name=&quot;accountService&quot;&gt;&lt;/param&gt;
      public AccountController(IAccountService accountService)
      {
          _accountService = accountService;
      }
  
      [HttpGet]
      [Route(&quot;IsAccountClosed/{nric}&quot;)]
      [ProducesResponseType(StatusCodes.Status200OK)]
      [ProducesResponseType(StatusCodes.Status204NoContent)]
      [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
      [ProducesResponseType(StatusCodes.Status404NotFound)]
      [ProducesResponseType(StatusCodes.Status500InternalServerError)]
      public async Task&lt;ActionResult&gt; IsAccountClosed([Required] string nric)
      {
          if (!ModelState.IsValid) {
              return UnprocessableEntity(ModelState);
          }     
      }
  }
  </code></pre>
  <p>I tried to remove the <code>ModelState</code> parameter in <code>UnprocessableEntity</code> to become <code>return UnprocessableEntity();</code></p>
  <p>But I can't see the data annotation validation details.</p>
  <p><a href="https://i.stack.imgur.com/hL0bU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hL0bU.png" alt="enter image description here" /></a></p>
  <p>Is it because of my <code>ValidationFilterAttribute</code>?</p>
  <pre><code>public class ValidationFilterAttribute : IActionFilter
  {
      public void OnActionExecuting(ActionExecutingContext context)
      {
          if (!context.ModelState.IsValid)
          {
             context.Result = new UnprocessableEntityObjectResult(context.ModelState);                
          }
      }
  
      public void OnActionExecuted(ActionExecutedContext context) { }
  }
  </code></pre>