title: Data gets lost in a POST request to server
body: <p>This is a really weird bug. I've got a redux action that gets form data and then sends it to the server as a jQuery.ajax. (I know, it's not good, but I'm not the one who wrote it that way)</p>
  <p>The bug only affects one field vehicle_id, the value being string.</p>
  <pre><code>    console.log('This gets sent', requestConfig) //This contains the stringified data. `vehicle_id` has the correct value.
      //It's the output of JSON.Stringify(data) with parameters like method and url added
      return new ApiRequest({
          dispatch: dispatch,
          getState: getState,
          config: requestConfig, // This is the same requestConfig, vehicle_id is null.
          done: function(data) {
              ...
          }
          ...
  </code></pre>
  <p>ApiRequest is a custom class. It passes the requestConfig as is to the jQuery.ajax function.</p>
  <p>What could be causing this behavior?</p>
  <p>The requestConfig (pasted from console from the console.log):</p>
  <pre><code>data: &quot;{\&quot;date\&quot;:\&quot;2021-05-10\&quot;,\&quot;warehouse_id\&quot;:\&quot;1\&quot;,\&quot;supplier_id\&quot;:\&quot;2\&quot;,\&quot;vehicle_id\&quot;:\&quot;301\&quot;,\&quot;suppliers_number\&quot;:\&quot;\&quot;,\&quot;note\&quot;:\&quot;\&quot;,\&quot;items\&quot;:[{\&quot;stock_item_id\&quot;:\&quot;\&quot;,\&quot;quantity\&quot;:1,\&quot;price\&quot;:0,\&quot;currency_id\&quot;:\&quot;8\&quot;},{\&quot;stock_item_id\&quot;:\&quot;\&quot;,\&quot;quantity\&quot;:1,\&quot;price\&quot;:0,\&quot;currency_id\&quot;:\&quot;8\&quot;},{\&quot;stock_item_id\&quot;:\&quot;\&quot;,\&quot;quantity\&quot;:1,\&quot;price\&quot;:0,\&quot;currency_id\&quot;:\&quot;8\&quot;}]}&quot;
  method: &quot;POST&quot;
  url: &quot;/goods-received-notes&quot;
  </code></pre>
  <p>ApiRequest class (the part that manages the config)</p>
  <pre><code>    import appConfig from '../config'
  import { refreshToken } from '../actions/auth'
  
  export function formatApiError(messageBase, xhr) {
      if (xhr.status === 422) { // Validation error
          let message = messageBase + '.';
  
          Object.keys(xhr.responseJSON).map((fieldName) =&gt; {
              message += '&lt;br&gt;' + xhr.responseJSON[fieldName];
          });
  
          return message;
      }
      else { // Any other error
          return messageBase + ': ' + xhr.responseJSON.message + '.';
      }
  }
  
  export class ApiRequest {
      constructor(options) {
          this.ajaxRequest = null;
  
          this.config = options.config;
          this.doneCallback = options.done;
          this.failCallback = options.fail;
  
          this.dispatch = options.dispatch;
          this.getState = options.getState;
      }
  
      run() {
          const dispatch = this.dispatch;
          const failCallback = this.failCallback;
          const repeatedRequest = this;
  
          let config = {
              ...this.config,
              url: appConfig.api.url + this.config.url,
              contentType: 'application/json',
              accept: 'application/json',
          }
  
          if (this.getState().user.object) {
              const token = this.getState().user.object.token;
  
              if (token) {
                  config.headers = {
                      ...config.headers,
                      Authorization: 'Bearer ' + token
                  }
              }
          }
  
          this.ajaxRequest = $.ajax(config)
              .done(this.doneCallback)
              .fail(function(xhr, exception) {
                      if (xhr.status === 401 &amp;&amp; xhr.responseJSON.message === 'Token has expired') {
                      let tokenRefreshResult = dispatch(refreshToken(repeatedRequest));
                  }
                      else if (exception !== 'abort' &amp;&amp; failCallback !== undefined) {
                      failCallback(xhr);
                  }
              });
      }
  
      abort() {
          this.ajaxRequest.abort();
      }
  }
  
  export class DownloadRequest {
      constructor(options) {
          this.config = options.config;
          this.getState = options.getState;
          this.newWindow = options.newWindow
      }
  
      run() {
          const token = this.getState().user.object.token;
          const url = appConfig.api.url + this.config.url + '?token=' + token;
  
          if (this.newWindow) {
              window.open(url);
          }
          else {
              window.location.assign(url);
          }
      }
  }
  
  export function ajax({ dispatch, getState, config, done, error } = {}) {
      let ajaxRequest = (repeatedRequest) =&gt; {
          $.ajax(config)
          .done(done)
          .fail(function(xhr) {
                  if (xhr.status === 401 &amp;&amp; xhr.responseJSON.message === 'Token has expired') {
                  let tokenRefreshResult = dispatch(refreshToken(
                      repeatedRequest
                  ));
              }
              else {
                  error(xhr);
              }
          });
      };
  
      ajaxRequest(ajaxRequest);
  }
  </code></pre>