Details
-
Type:
Bug
-
Status: Open
-
Priority:
Medium
-
Resolution: Unresolved
-
Component/s: Foundation
-
Labels:
-
Environment:
swift-4.1-DEVELOPMENT-SNAPSHOT-2017-12-15-a
-
Radar URL:
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)) }