ObjectMapper failed to serialize response

Created on 5 Nov 2015  路  2Comments  路  Source: tristanhimmelman/ObjectMapper

I'm noticing a weird issue that I can't seem the reason for.

I have a Log In view controller, after the user authenticates, I load an Event view controller and on the viewDidLoad() function, I fetch data from the end point using the getEvents method

class func getEvents(forEventId eventId: Int?, completionHandler: (events: [Event]?, err: ErrorType?) -> Void) {

        Alamofire.request(API.Router.getEvents())
            .responseArray { (response: Response<[Event], NSError>) in
                switch response.result {

                case .Success(let data):
                    if response.response?.statusCode == 200 || response.response?.statusCode == 201 {
                        completionHandler(events: data, err: nil)
                    }
                    else {
                        if let error = response.result.value as? ErrorType {
                            completionHandler(events: nil, err: error)
                        }
                    }

                case .Failure(let error):
                    debugPrint("getEvents error: \(error)")
                }
            }
    }

but it throws the following error and the process dies:

"getEvents error: Error Domain=com.alamofire.error Code=-6004 \"The operation couldn鈥檛 be completed.
ObjectMapper failed to serialize response.\" UserInfo=0x7f9f71596240
{NSLocalizedFailureReason=ObjectMapper failed to serialize response.}"

However, if I had just rebuild the application and run it again, ObjectMapper serializes the response just fine and the events model is filled.

Has anyone seen this type of issue before? Any pointer is appreciated.

Most helpful comment

It's hard to say, but it sounds to me like there may be an authentication issue when you make the first call to get events.
Can you print out the response string when the call fails to give use more info. You can do that by appending the following after the responseArray closure

.responseString { response in
                print("Success: \(response.result.isSuccess)")
                print("Response String: \(response.result.value)")
        }

All 2 comments

It's hard to say, but it sounds to me like there may be an authentication issue when you make the first call to get events.
Can you print out the response string when the call fails to give use more info. You can do that by appending the following after the responseArray closure

.responseString { response in
                print("Success: \(response.result.isSuccess)")
                print("Response String: \(response.result.value)")
        }

@tristanhimmelman - the issue turns out to be a logic error on my part. Nothing to do with ObjectMapper :-)

:+1: for the quick response. Your suggestion to add the .responseString certainly helped resolve it.

Closing issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhengying picture zhengying  路  4Comments

nashirox picture nashirox  路  4Comments

liltimtim picture liltimtim  路  3Comments

VictorAlbertos picture VictorAlbertos  路  3Comments

amg1976 picture amg1976  路  3Comments