title: How to override Json.Net model binding exception messages for localization purposes?
body: <p>I've overridden all model binding messages with translations using <code>ModelBindingMessageProvider.SetValueIsInvalidAccessor</code> and other ModelBindingMessageProvider values to return my custom resource strings.</p>
  
  <p>And then I discovered the sad truth. If my API controller receives the data as JSON, then ModelBindingMessageProvider validation messages are not being used. Instead, Json.Net kicks in and I get something like this in response:</p>
  
  <pre><code>  "errors": {
      "countryId": [
        "Input string '111a' is not a valid number. Path 'countryId', line 3, position 23."
      ]
    },
  </code></pre>
  
  <p>I looked in GitHub source of Json.Net - indeed, it seems to have such exact error messages defined with line numbers etc.</p>
  
  <p>So, ModelState manages to pull them in instead of using its own ModelBindingMessageProvider messages.</p>
  
  <p>I tried to disable Json.Net error handling:</p>
  
  <pre><code>.AddJsonOptions(options =&gt;
                  {
                   ...
                      options.SerializerSettings.Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
                      {
                          // ignore them all
                          args.ErrorContext.Handled = true;
                      };
                  })
  </code></pre>
  
  <p>but it made no difference.</p>
  
  <p>Is there any way to catch these Json deserialization errors and redirect them to ModelBindingMessageProvider, so that my localized messages would work?</p>