-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-7992] JSONEncoder should allow custom key ordering behavior #3676
Comments
cc @itaiferber |
Although this sounds like a relatively simple request, I think in practice there would be quite a bit of complication here due to the fact that I'm not sure how generally applicable this feature would be—as you say yourself, this isn't really a valid requirement on the JSON—but something we could definitely consider. This would be easier if |
@swift-ci create |
Ah, that's a good explanation. I had assumed that because lexographic key sorting is offered that this was something that might be easy to hook into. |
@subdigital Yeah, that was significantly easier to do because we introduced a similar option on |
Comment by Damian Mehers (JIRA) I've just hit this issue, converting .NET code to Swift. I'm talking to an Amazon service over which I have no control, and it gives an error if the keys are not ordered as they specify. I lost many many hours because of this - most of which were caused by me not believing that the service could require a specific field ordering ... but it does ... is there any recommended approach if ordering is required to be preserved, other than rolling my own encoder? |
Additional Detail from JIRA
md5: b325e74ffe4c72ee5ea685cb2c3ee15b
Issue Description:
I am working with a server that requires a certain key to be present first in an object ("for performance reasons" they said)...
Unfortunately, implementing `encode(to🙂` manually and encoding in a specific order does not end up having any effect on the key order of the resulting document.
Discussions about key order not being a valid JSON concern aside (which I agree with) it would be nice to have functionality for determining the order of keys by providing a custom function, similar to how we handle custom date formatting logic.
I'd love to have something like this:
(And if Radar is a better place for this I'd be happy to submit it there instead.)
The text was updated successfully, but these errors were encountered: