I have the following Swift code.
class Person: Codable {
var born: Date
}
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
do {
let person = try decoder.decode(Person.self, from: "{\"born\": \"2017-12-04T23:24:09.853Z\"}".data(using: .utf8)!)
} catch {
print(error)
}
I expect this to return a Person object with a born date of 2017-12-04T23:24:09.853Z (which from what I can gather is a fully valid ISO8601 date).
Instead I get an error dataCorrupted(Swift.DecodingError.Context(codingPath: [__lldb_expr_1.Person.(CodingKeys in _1Q81646826320N3Z86BD5V078M06H287).born], debugDescription: "Expected date string to be ISO8601-formatted.", underlyingError: nil)).
According to Swift it looks like my date string is not ISO8601-formatted even tho I'm pretty confident it is (according to this NPM Package, and this answer).
What am I doing wrong here?