swift - SwiftyJSON order of elements inside JSON object -


i'm using swiftyjson serialize/deserialize json data when communicating entityframework backend. problem - endpoints ef expects see "__type" attribute map .net class in backend. , "__type" attribute must first attribute of json object.

here example of working payload:

"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     }   ] 

that works fine. if reason __type move lower in object - server fails. now, know can't guarantee order of elements in dictionary, how else can worked out?

i'm creating json object in swift this:

return json([     "__type": "outside_vendors_to_events:#qpweboffice.web",     "event_id": eventid,     "id": id,     "revenue": revenue,     "transactions_count": transactioncount,     "vendor": name == nil ? nsnull() : name! ]) 

the order seems same always, it's different different classes have in app. , of them - regardless of - "__type" end in middle of json properties.

any idea appreciated. , no, can't change server.

dictionaries are, design, not stable on insertion order (insertion order doesn't matter when iterating keys) ef arguably broken in requiring order of js objects, isn't specified. said, might able solve problem using answers question: insertion-order dictionary (like java's linkedhashmap) in swift?. barring that, you'll need customize serialization operation (whatever turns dictionary json) special case this.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -