Open nitishmaropost opened 5 years ago
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": "a@b.com", "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 :
responseObject
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.
User model :
Actual JSON :
Alamofire request :
Crash received on
responseObject
:Note : The request works fine. When I try a simple Alamofire request, it works :
Important : Tested the library's sample (WeatherResponse on home page). It gives the same crash.