Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requestObject crashes while converting JSON to object #274

Open
nitishmaropost opened this issue May 20, 2019 · 0 comments
Open

requestObject crashes while converting JSON to object #274

nitishmaropost opened this issue May 20, 2019 · 0 comments

Comments

@nitishmaropost
Copy link

nitishmaropost commented May 20, 2019

User model :

import Foundation
import ObjectMapper

class User: Mappable {
    
    // Variables
    var userInfo: UserInfo?
    var token: String?
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        self.userInfo <- map["user_info"]
        self.token <- map["token"]
    }
}

class UserInfo: Mappable {
    
    // Variables
    var fullName: String?
    var firstName: String?
    var lastName: String?
    var email: String?
    var employeeCode: Int?
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        self.fullName <- map["full_name"]
        self.firstName <- map["first_name"]
        self.lastName <- map["last_name"]
        self.email <- map["email_id"]
        self.employeeCode <- map["emp_code"]
    }
    
}

Actual JSON :

{
    "user_info": {
        "full_name": "test full name",
        "first_name": "test first name",
        "last_name": "test last name",
        "email_id": "[email protected]",
        "emp_code": 111
    },
    "token": "------"
}

Alamofire request :

AF.request("\(TimelyUrls.shared.kServerUrl)\(TimelyUrls.shared.kLoginUrl)", method: .post, parameters: requestDict, encoding: JSONEncoding.default, headers: TimelyUrls.shared.HEADER).responseObject { (response: DataResponse<User>) in
            print(response.result)
}  

Crash received on responseObject :

enter image description here

Note : The request works fine. When I try a simple Alamofire request, it works :

AF.request("\(TimelyUrls.shared.kServerUrl)\(TimelyUrls.shared.kLoginUrl)", method: .post, parameters: requestDict, encoding: JSONEncoding.default, headers: TimelyUrls.shared.HEADER).responseJSON { (response) in
            print(response)
}  

Important : Tested the library's sample (WeatherResponse on home page). It gives the same crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant