title: Order of object properties is changed while posting data from ionic native http client
body: <p>I am working on ionic app which will be used on android and iOS platforms. App uses one endpoint to post user data to the backend. Data posted on a backend is as follows:</p>
  
  <pre><code>{
    "name": "Citizen Foo",
    "emailAddress": "citizen.foo@gmail.com",
    "role": "citizen"
  }
  </code></pre>
  
  <p>For security purpose every request which is being sent is validated. In order to do this client sends authorization header with every request. Backend creates one for every request and matches it with one sent by client and then only responds otherwise throw an exception. For creating the authorization header, data sent over post request is also a part of the logic. I have simplified this logic becuase the actual problem is different but this part is important to understand the problem.</p>
  
  <p>Following is the sample code on client side:</p>
  
  <pre><code>var sRequestBody = JSON.stringify(data);
  var requestBodyBytes = this.getByteArray(unescape(encodeURIComponent(sRequestBody)));
  var authHeader = md5.base64(requestBodyBytes);
  var headers = {};
  headers['Authorization'] = authHeader;
  this.nativeHttp.setDataSerializer('json');
  this.nativeHttp.clearCookies();
  this.nativeHttp.setSSLCertMode('nocheck');
  return Observable.fromPromise(this.nativeHttp.post(url, data, headers));
  </code></pre>
  
  <p>Then, backend which is asp.net web api, calculates authorization in the same way and matches it with one send by client and gives the response if it matches.</p>
  
  <pre><code>var rawContent = await content.ReadAsByteArrayAsync();
  var stringContent = content.ReadAsStringAsync().Result;
  var hash = md5.ComputeHash(rawContent);
  var authorization = Convert.ToBase64String(hash);
  if (authHeader != authorization)
      throw;
  </code></pre>
  
  <p>When the above call is made from android, </p>
  
  <pre><code>value of dataString on client is 
  "{"name":"Citizen Foo","emailAddress":"citizen.foo@gmail.com","role":"citizen"}"
  value of stringContent on server is 
  "{""name"":""Citizen Foo"",""emailAddress"":""citizen.foo@gmail.com"",""role"":""citizen""}"
  </code></pre>
  
  <p>and it allows request coming from android app.</p>
  
  <p>When the same is run on iOS and the post user call is made,</p>
  
  <pre><code>Value of dataString on client is 
  "{"name":"Citizen Foo","emailAddress":"citizen.foo@gmail.com","role":"citizen"}"
  Value of stringContent on server is 
  "{""name"":""Citizen Foo"",""role"":""citizen"",""emailAddress"":""citizen.foo@gmail.com""}"
  </code></pre>
  
  <p>and it does not allow requst coming from iOS app.</p>
  
  <p>And the only reason it is happening is because of the way user object is serialized/received at the backend when request is made from iOS. Order of properties while sending is <code>name,emailAddress,role</code>. While it is received with order <code>name,role,emailAddress</code>. Thus, the authorization value calculated on server side is different than authHeader coming from client and the call is terminated. </p>
  
  <p><code>stringContent</code> was added on server side just to debug and understand what is being received at server. Order of the object properties on client is different than object properties received on server side. Is there a way to maintain the order of object properties when the request is made from iOS platform? Direction in any way to solve this problem is appreciated.</p>