Objectmapper: Int64 variables not parsed correctly

Created on 28 Feb 2017  路  4Comments  路  Source: tristanhimmelman/ObjectMapper

Since the latest release (2.2.4), Int64s are only mapped correctly if the variable is an IUO (Int64!). It does not map optional (Int64?) or non-optional Int64s. Until 2.2.3 it used to work without problem.

Your JSON dictionary:

let myJSONDictionary: [String: Any] = [
    "64BitInt": Int64(123),
    "64BitIUOInt": Int64(321),
    "64BitNonOptionalInt": Int64(456),
    "regularInt": 654
]

Your model:

class Item: Mappable {
    var my64BitInt: Int64?
    var my64BitIOUInt: Int64!
    var my64BitNonOptionalInt: Int64 = 0
    var regularInt: Int?

    required init(map: Map) {
        mapping(map: map)
    }

    func mapping(map: Map) {
        my64BitInt <- map["64BitInt"]
        my64BitIOUInt <- map["64BitIUOInt"]
        my64BitNonOptionalInt <- map["64BitNonOptionalInt"]
        regularInt <- map["regularInt"]
    }
}

What you did:

let item = Mapper<Item>().map(JSON: myJSONDictionary)

What you expected:

I exepected something like:

Item(my64BitInt: 123, my64BitIOUInt: 321, my64BitNonOptionalInt: 456, regularInt: 654) 

What you got:

Item(my64BitInt: nil, my64BitIOUInt: 321, my64BitNonOptionalInt: 0, regularInt: 654)  // expected the Int64? and Int64 is mapped correctly.

Most helpful comment

Thanks!! Awesome this quick response @devxoul and @tristanhimmelman. You're the best!

All 4 comments

Oh god, this is my fault. I'll check this right now. I apologize for my mistake!

766 is the patch for this issue

Just created a new release with this fix. See 2.2.5

Thanks!! Awesome this quick response @devxoul and @tristanhimmelman. You're the best!

Was this page helpful?
0 / 5 - 0 ratings