[iOS 17 beta] Unexpected behaviour of codingPath for JSONDecoder

Hi!

After iOS 17 beta release we started getting negative feedback from our users. While researching the issue I found out that the value of codingPath on iOS 17 is different from one on iOS 16.

Example to reproduce this

import Foundation

class DynamicCodingKey: CodingKey {
    let stringValue: String
    required init?(stringValue: String) {
        self.stringValue = stringValue
    }

    var intValue: Int? { return nil }
    required init?(intValue: Int) { return nil }
}

struct Response: Decodable {
    enum CodingKeys: String, CodingKey {
        case content
    }

    public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)

        let contentContainerCodingKey = DynamicCodingKey(stringValue: "dynamicValue")
        let contentContainer = try container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .content)


        try contentContainer.decode(Content.self, forKey: contentContainerCodingKey!)
    }
}

struct Content: Decodable {
    public init(from decoder: Decoder) throws {
        print("---> \(decoder.codingPath)")

        throw NSError()
    }
}


let exampleString = """
{
  "content": {
    "dynamicValue": {
      "keyA": 4,
      "keyB": "dynamicValue",
    }
  }
}
"""


let exampleData = exampleString.data(using: .utf8)!

do {
    try JSONDecoder().decode(Response.self, from: exampleData)
} catch {

}

print output for XCode 14 playground or iOS 16:

---> [DynamicCodingKey(stringValue: "dynamicValue", intValue: nil)]

print output for XCode 15 playground or iOS 17:

---> [CodingKeys(stringValue: "content", intValue: nil), DynamicCodingKey(stringValue: "dynamicValue", intValue: nil)]

Could you tell it is expected behaviour since iOS 17 or bug?

After iOS 17 beta release we started getting negative feedback from our users. While researching the issue I found out that the value of codingPath on iOS 17 is different from one on iOS 16.

If this is breaking existing products, you should definitely file a bug report about it; please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I faced the same problem on xcode 15 and ios 17 simulator. But actually, ios 16.4 simulator on xcode 15 doesn't have such problems.

[iOS 17 beta] Unexpected behaviour of codingPath for JSONDecoder
 
 
Q