Skip to content
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

OrderedDictionary decoding. #310

Closed
2 tasks done
SVN93 opened this issue Aug 18, 2023 · 1 comment
Closed
2 tasks done

OrderedDictionary decoding. #310

SVN93 opened this issue Aug 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@SVN93
Copy link

SVN93 commented Aug 18, 2023

Information

  • Package version: 1.0.4
  • Swift version: 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • I've searched for existing GitHub issues.

Steps to Reproduce

Try to decode an OrderedDictionary from this JSON:

"Value": {
    "SalespersonID": "SP0003",
    "Name": "Steve Church"
}

The original Dictionary accepts such a format, but the OrderedDictionary expects the array of the key-value pairs which is a serious limitation in decoding.

Expected behavior

The OrderedDictionary should be decoded as a regular Dictionary.

Actual behavior

Expected to decode Array but found a dictionary instead.

@SVN93 SVN93 added the bug Something isn't working label Aug 18, 2023
@lorentey
Copy link
Member

OrderedDictionary needs to guarantee that the order of its items will not change during serialization/deserialization. This is not guaranteed by Codable's keyed containers -- therefore they aren't suitable for use by OrderedDictionary.

Note that Codable is a common denominator archival solution, primarily intended for use where you don't care about the precise details of the serialized format. It is the Swift version of NSCoding, or Python's pickle. Codable is emphatically not a flexible JSON encoder/decoder that's designed to interoperate with arbitrary JSON APIs.

#12 (comment)

@lorentey lorentey closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants