ObjectMapper icon indicating copy to clipboard operation
ObjectMapper copied to clipboard

In argument type 'String.Type', 'String' does not conform to expected type 'Mappable'

Open sheng930920 opened this issue 6 years ago • 2 comments

let's say I have a json object that might look like this:

{
  "code": 0,
  "result": "https://github.com/Hearst-DD/ObjectMapper",
  "msg": "Unknown error, please check with Admin."
}

My model:

class HttpResponse<T : Mappable> : Mappable {
    
    var code: Int = 0
    var msg: String?
    var result: T?
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        code    <- map["code"]
        msg    <- map["msg"]
        result    <- map["result"]
    }
    
}


class User: Mappable {
    var username: String?
    var age: Int?
    var weight: Double!
    var array: [Any]?
    var dictionary: [String : Any] = [:]
    var bestFriend: User?                       // Nested User object
    var friends: [User]?                        // Array of Users
    var birthday: Date?

    required init?(map: Map) {

    }

    // Mappable
    func mapping(map: Map) {
        username    <- map["username"]
        age         <- map["age"]
        weight      <- map["weight"]
        array       <- map["arr"]
        dictionary  <- map["dict"]
        bestFriend  <- map["best_friend"]
        friends     <- map["friends"]
        birthday    <- (map["birthday"], DateTransform())
    }
}


But the value of result is generic, the value type has String, or the entity object like User, when I pass in the String error, the prompt 'String' does not conform to expected type 'Mappable'

I did:


let result1 = Mapper<HttpResponse<User>>().map(JSON)

let result2 = Mapper<HttpResponse<String>>().map(JSON)

result2 tost the prompt 'String' does not conform to expected type 'Mappable'

I exepected something like:

let result2 = Mapper<HttpResponse<String>>().map(JSON)

sheng930920 avatar Aug 20 '18 07:08 sheng930920

I am having the same issue.

nawinkhatiwada avatar Dec 30 '18 09:12 nawinkhatiwada

any luck with this issue ?

SoufianHossam avatar Mar 07 '19 23:03 SoufianHossam