Open
Description
Previous ID | SR-6629 |
Radar | rdar://problem/41038908 |
Original Reporter | @norio-nomura |
Type | Bug |
Environment
swift-4.1-DEVELOPMENT-SNAPSHOT-2017-12-15-a
Additional Detail from JIRA
Votes | 1 |
Component/s | Foundation |
Labels | Bug, Codable |
Assignee | @itaiferber |
Priority | Medium |
md5: fee6142a597261d7125a4f80b8b8ceb2
Issue Description:
Because JSONDecoder
coverts my_url_property
to myUrlProperty
.
import Foundation
struct S: Codable {
var myURLProperty: String
}
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
let data = try encoder.encode(S(myURLProperty: "property"))
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
do {
let decoded = try decoder.decode(S.self, from: data)
} catch {
print(error)
// keyNotFound(CodingKeys(stringValue: "myURLProperty", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"myURLProperty\", intValue: nil) (\"myURLProperty\"), converted to my_url_property.", underlyingError: nil))
}