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
superDecoder(forKey:)
When trying to decode a Codable model with following implementation:
Codable
struct SomeCodable { let value1: String? } extension SomeCodable: Decodable { init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) if let key1_containerDecoder = try? container.superDecoder(forKey: CodingKeys.key1) { let key1_container = try key1_containerDecoder.container(keyedBy: CodingKeys.self) self.value1 = try key1_container.decodeIfPresent(String.self, forKey: CodingKeys.value1) } else { self.value1 = nil } } } extension SomeCodable: Encodable { func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) var key1_container = container.nestedContainer(keyedBy: CodingKeys.self, forKey: CodingKeys.key1) try key1_container.encodeIfPresent(self.value1, forKey: CodingKeys.value1) } } extension SomeCodable { enum CodingKeys: String, CodingKey { case value1 = "key2" case key1 = "key1" } }
and empty JSON object({}) error is thrown at
{}
let key1_container = try key1_containerDecoder.container(keyedBy: CodingKeys.self)
valueNotFound(Swift.KeyedDecodingContainer<MetaCodableTests.SomeCodable.CodingKeys>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "key1", intValue: nil)], debugDescription: "Cannot get keyed decoding container -- found null value instead.", underlyingError: nil))"
instead of
if let key1_containerDecoder = try? container.superDecoder(forKey: CodingKeys.key1)
which is diferrent than documented.
As per discussion in forum, both older and new Foundation implementation seems to have this bug.
Foundation
The text was updated successfully, but these errors were encountered:
No branches or pull requests
When trying to decode a
Codable
model with following implementation:and empty JSON object(
{}
) error is thrown atinstead of
which is diferrent than documented.
As per discussion in forum, both older and new
Foundation
implementation seems to have this bug.The text was updated successfully, but these errors were encountered: