tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.13k stars 1.03k forks source link

Crash Mapper initializer when running in a XCTestCase #1117

Open ppamorim opened 3 years ago

ppamorim commented 3 years ago

Your JSON dictionary:

{
  "id": 123,
  "name": "Pedro"
}

Your model:

@objc
final class User: RealmSwift.Object, Mappable {

  var id: Int = -1
  var name: String = ""

  required convenience init?(map: Map) {
    self.init()
  }

  init(_ map: Map) {
    id <- map["id"]
    name <- map["name"]
  }
}

What you did:

let users = Mapper<User>().mapArray(JSONString: string)

What you expected:

I exepected something like:

[User]

What you got:

Screenshot 2021-04-10 at 01 23 43

The crash happens when the unit test calls Mapper<User>(), I tried to replace it with Mapper<User>(shouldIncludeNilValues: true) and tried to remove final from the class User but no success.

Xcode: 12.4 Cocoapods: 1.10.1 (It's not using use_frameworks! nor use_modular_headers!) Swift: 5.3.2

crownvic commented 3 years ago

@ppamorim, have you solved this problem? I have the same issue when Mapper<Object> works anywhere except test classes.

ppamorim commented 3 years ago

@crownvic Not yet, We cannot use the library anymore. We are migrating to Decodable.