-
Notifications
You must be signed in to change notification settings - Fork 44
Wrong keyPath message on DecodeError.TypeMismatch #120
Copy link
Copy link
Closed
Description
decodeValue reports the wrong keyPath.
The TypeMismatch error below should be like this
TypeMismatch(expected: Int, actual: String, keyPath: KeyPath(["displayType"]))
, instead of this
TypeMismatch(expected: Int, actual: Optional(), keyPath: KeyPath(["dialog"]))
Test Code
let json = loadJson("videoFileList_error.json") as! JSON
let _: ErrorObject.Data = try! decodeValue(json["error"]!["data"]!)
struct ErrorObject: Decodable {
let code: Int
let message: String
let data: Data?
struct Data: Decodable {
let dialog: Dialog?
let url: String?
struct Dialog: Decodable {
let title: String?
let message: String?
let displayType: Int?
{
"result": null,
"error": {
"code": 110,
"message": "",
"data": {
"dialog": {
"title": "",
"message": "",
"displayType": "" // This causes TypeMismatch because it's String instead of expected Int?.
},
"url": null
}
},
"id": "1",
"jsonrpc": "2.0"
}
Reactions are currently unavailable