SwiftyJSON order of elements inside JSON object
<p>I'm using SwiftyJSON to serialize/deserialize JSON data when communicating with EntityFramework backend. Problem is - for some endpoints EF expects to see "__type" attribute to properly map it to .NET class in the backend. And this "__type" attribute <strong>must</strong> be very first attribute of the JSON object. </p>

<p>Here are example of working payload:</p>

<pre><code>"changeSet" : [
    {
      "OriginalEntity" : {
        "__type" : "outside_vendors_to_events:#QPWebOffice.Web",
        "revenue" : 0,
        "transactions_count" : 23,
        "id" : 8,
        "vendor" : "New",
        "event_id" : 4
      },
      "Operation" : 3,
      "Entity" : {
        "__type" : "outside_vendors_to_events:#QPWebOffice.Web",
        "revenue" : 0,
        "transactions_count" : 2,
        "id" : 8,
        "vendor" : "New",
        "event_id" : 4
      },
      "Id" : 0
    }
  ]
</code></pre>

<p>That works fine. But if for some reason __type will get move lower in the object - server fails. Now, I know that you can't guarantee order of elements in dictionary, but how else that can be worked out? </p>

<p>I'm creating JSON object in Swift like this:</p>

<pre><code>return JSON([
    "__type": "outside_vendors_to_events:#QPWebOffice.Web",
    "event_id": eventId,
    "id": id,
    "revenue": revenue,
    "transactions_count": transactionCount,
    "vendor": name == nil ? NSNull() : name!
])
</code></pre>

<p>The order seems to be same always, but it's different for different classes I have in the app. And for some of them - regardless of what I do - "__type" will end up in the middle of JSON properties. </p>

<p>Any idea would be greatly appreciated. And no, I can't change server. </p>