We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Swift 5.0
md5: 076bfab4f40c06914f7da38d175cf6d4
Issue Description:
I'm trying to encode and decode a Codable struct that has a double optional (e.g. name: String??).
name: String??
This way, encoding the struct with the JSONEncoder, I get a json with:
.some
.none: {
.some(.none)
Trying to decode this json again does not handle the third case correctly, the decoded value is .none (like the second case):
.none
import Foundation struct S: Codable { let name: String?? } let a = S(name: "123") let jsonA = try! JSONEncoder.init().encode(a) // { name: "123" } let a2 = try! JSONDecoder().decode(S.self, from: jsonA) assert(a2.name == .some("123")) let b = S(name: nil) let jsonB = try! JSONEncoder.init().encode(b) // {} let b2 = try! JSONDecoder().decode(S.self, from: jsonB) assert(b2.name == .none) let c = S(name: .some(nil)) // or .some(.none) let jsonC = try! JSONEncoder.init().encode(c) // { name: null } let c2 = try! JSONDecoder().decode(S.self, from: jsonC) assert(c2.name == .some(.none)) // fails the assertion, because c2.name == .none
The problem is the last line, c2.name is .none and not .some(.none) as expected.
c2.name
The text was updated successfully, but these errors were encountered:
I don't think that's what the default synthesized init(coder:) does. It seems like reasonable behavior for it to do so, though.
init(coder:)
Sorry, something went wrong.
No branches or pull requests
Environment
Swift 5.0
Additional Detail from JIRA
md5: 076bfab4f40c06914f7da38d175cf6d4
Issue Description:
I'm trying to encode and decode a Codable struct that has a double optional (e.g.
name: String??
).This way, encoding the struct with the JSONEncoder, I get a json with:
.some
: { name: "123" }.none: {
}.some(.none)
: { name: null }Trying to decode this json again does not handle the third case correctly, the decoded value is
.none
(like the second case):The problem is the last line,
c2.name
is.none
and not.some(.none)
as expected.The text was updated successfully, but these errors were encountered: