-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[WIP] Using RawRepresentable String keys for Dictionaries with JSONEncoder and JSONDecoder #26257
[WIP] Using RawRepresentable String keys for Dictionaries with JSONEncoder and JSONDecoder #26257
Conversation
Update to apple/swift master
…sentable String keyed Dictionaries to/from keyed containers
Things that I would very much like input on: The name of the option is currently not very good. I have a real hard time coming up with a good and descriptive name. Is the concept of using 'encode' and 'decode' for the keys ok? I think that it's a natural thing to do, but currently I have hacked around the 'canEncodeNewValue' by pushing a dummy key on the How do you properly add availability flags for the next swift version? |
@itaiferber have you had a chance to look at my take on this? |
@mortenbekditlevsen Sorry, I didn't see this when you originally put this up. I'll try to getting to review it as soon as I can. :) |
@itaiferber Do you think there’s perhaps a better way to achieve this? |
@itaiferber Sorry for pestering you. Have you by any chance had time to consider this? |
@mortenbekditlevsen Not pestering! Though unfortunately, I can't be of much help anymore as I no longer work at Apple. @parkera might have a suggestion for who should review this instead. |
Hi @itaiferber , |
Thanks, @mortenbekditlevsen! I appreciate that, and wish the same to you! 😄 |
I'd like to keep considering this concept (perhaps more in the thread since there are other ideas there). I don't have a concrete answer yet on when we should do it though. |
Hi @parkera , Unfortunately I have not received any feedback for my latest post yet. |
I think the best thing I can do for this is file a radar for us to track it internally. That doesn't provide any guarantee of when we'll have the bandwidth to work on it, but it will ensure that we don't lose it. I have gone ahead and done that (rdar://problem/57410395) |
I will close this issue, as my personal opinion for how to solve this has changed. |
Some Internet searches are still directing here so note there is now Swift Language support for this in the form of |
Currently
Dictionary
will encode and decode kay/value pairs to unkeyed containers in case the key is notString
orInt
.This PR is a WIP implementation of a workaround specifically for
JSONEncoder
andJSONDecoder
that is hidden behind an option in order to make it backwards compatible with the current implementation.The issue is briefly discussed here: https://forums.swift.org/t/using-rawrepresentable-string-and-int-keys-for-codable-dictionaries/26899
The PR partly deals with the issue:
https://bugs.swift.org/browse/SR-7788
but only with regard to
String
RawRepresentable
keys - and only for theJSONEncoder
andJSONDecoder
.