We are using Alamofire with Moya and Moya-ObjectMapper, to handle the API calls. Response from server is as below:
{
"userid" : "1",
"token" : "abc"
}
ObjectMapper is unable to handle this and always throws exception.
Error info: JSONMapping(Status Code: 200, Data Length: 313)
At the same time, it is able to handle response in this format:
[
{
"email":["validation.unique"]
}
]
I verified that the JSON response is in proper format. My code snippet is here:
struct SignupNLoginResponse: Mappable {
var token: String?
var userID: String?
init?(_ map: Map){
}
mutating func mapping(map: Map) {
token <- map["token"]
userID <- map["user_id"]
}
}
@IBAction func processSignUp () {
SnLInput.name = "Celine Peter"
SnLInput.email = "[email protected]"
SnLInput.password = "testing@123"
provider.request(AppTarget.signUp, completion: { result in
var success = true
var message = "Unable to signup"
switch result {
case let .Success(response):
do {
let outputString:NSString! = NSString(data:response.data, encoding:NSUTF8StringEncoding)
print(outputString)
if let repos: [SignupNLoginResponse]? = try response.mapObjectMapper() {
print(repos)
} else {
success = false
}
} catch {
success = false
print("Error info: \(error)")
}
case let .Failure(error):
guard let error = error as? CustomStringConvertible else {
break
}
message = error.description
}
print(message)
print(success)
})
}
This is our first project using these libraries and we couldn't understand what we are missing. We appreciate any help, pointing us in the right direction. Please let know if any information found missing to figure out the issue.
