ObjectMapper icon indicating copy to clipboard operation
ObjectMapper copied to clipboard

Mapping Generics and primitive data types

Open cordechasse opened this issue 6 years ago • 1 comments

Hi,

Can we use primitive data types as Generics?

Here's my JSON:

{
  "result": 33
}

Here's my Model:

class Result<T: Mappable>: Mappable {
    var result: T?

    required init?(map: Map){

    }

    func mapping(map: Map) {
        result <- map["result"]
    }
}

What I did:

let result = Mapper<Result<Int>>().map(JSON)

I've got a compiler error:

Type 'Int' does not conform to protocol 'Mappable'

Is there any workaround?

cordechasse avatar Oct 05 '18 08:10 cordechasse

Instead of this:

class Result<T: Mappable>

do this:

class Result<T>

Because Int does not implement Mappable protocol.

gim- avatar Apr 03 '19 11:04 gim-