Skip to content

Wrong keyPath message on DecodeError.TypeMismatch #120

@toshi0383

Description

@toshi0383

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"
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions