{"action":"opened","issue":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/854","labels_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/854/labels{/name}","comments_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/854/comments","events_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/854/events","html_url":"https://github.com/Alamofire/Alamofire/issues/854","id":111094984,"number":854,"title":"How to custom response serialization","user":{"login":"jumpingfrog0","id":7556575,"avatar_url":"https://avatars.githubusercontent.com/u/7556575?v=3","gravatar_id":"","url":"https://api.github.com/users/jumpingfrog0","html_url":"https://github.com/jumpingfrog0","followers_url":"https://api.github.com/users/jumpingfrog0/followers","following_url":"https://api.github.com/users/jumpingfrog0/following{/other_user}","gists_url":"https://api.github.com/users/jumpingfrog0/gists{/gist_id}","starred_url":"https://api.github.com/users/jumpingfrog0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jumpingfrog0/subscriptions","organizations_url":"https://api.github.com/users/jumpingfrog0/orgs","repos_url":"https://api.github.com/users/jumpingfrog0/repos","events_url":"https://api.github.com/users/jumpingfrog0/events{/privacy}","received_events_url":"https://api.github.com/users/jumpingfrog0/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-13T03:13:38Z","updated_at":"2015-10-13T03:13:38Z","closed_at":null,"body":"I use Alamofire-beta3, I want to custom response serialization, but I get a error \"Cannot call value of non-function type 'NSHTTPURLResponse?' \"\r\n\r\nMy code is below:\r\n\r\npublic static func objectSerializer<T: MTLModel>() -> ResponseSerializer<T, MTLError> {\r\n        \r\n        return ResponseSerializer { request, response, data, error in\r\n            \r\n            // Http Error with Http status code\r\n            guard error == nil else {\r\n                let failureReason = \"Network Error\"\r\n                let error = MTLError.errorWithCode(error!.code, failureReason: failureReason)\r\n                return .Failure(error)\r\n            }\r\n            \r\n            // data be null\r\n            guard let validData = data where validData.length > 0 else {\r\n                let failureReason = \"JSON could not be serialized. Response data was nil or zero length.\"\r\n                let error = MTLError.errorWithCode(.ResponseDataNull, failureReason: failureReason)\r\n                return .Failure(error)\r\n            }\r\n            \r\n            do {\r\n                let JSON = try NSJSONSerialization.JSONObjectWithData(validData, options: .AllowFragments)\r\n                \r\n                // response data is not a obejct json\r\n                guard let json = JSON as? [String : AnyObject] else {\r\n                    let failureReason = \"JSON could not be serialized. Response data is not a obejct JSON\"\r\n                    let error = MTLError.errorWithCode(.JSONSerializeToObjectFailed, failureReason: failureReason)\r\n                    return .Failure(error)\r\n                }\r\n                \r\n                // Http request successful(state 200 OK), but response data not include `Error Section`\r\n                guard let errorDict = json[\"error\"] as? [String : AnyObject] else {\r\n                    let failureReason = \"JSON could not be serialized. Http request successful(state 200 OK), but response data not include `Error Section`\"\r\n                    let error = MTLError.errorWithCode(.JSONSerializeErrorSectionFailed, failureReason: failureReason)\r\n                    return .Failure(error)\r\n                }\r\n                \r\n                // mean request failed\r\n                if errorDict.count != 0 {\r\n                \r\n                    let error: MTLError!\r\n                    do {\r\n                        error = try MTLJSONAdapter.modelOfClass(MTLError.self, fromJSONDictionary: errorDict) as! MTLError\r\n                    } catch _ {\r\n                        let failureReason = \"MTLError object serialize failed\"\r\n                        error = MTLError.errorWithCode(.JSONSerializationFailed, failureReason: failureReason)\r\n                    }\r\n                    return .Failure(error)\r\n                \r\n                } else {\r\n                    // mean request successful\r\n                    let dataDict = json[\"data\"] as? [String : AnyObject]\r\n                    \r\n                    do {\r\n                        let object = try MTLJSONAdapter.modelOfClass(T.self, fromJSONDictionary: dataDict) as! T\r\n                        return .Success(object)\r\n                    } catch _ {\r\n                        let failureReason = \"\\(T.self) object serialize failed\"\r\n                        let error = MTLError.errorWithCode(.JSONSerializationFailed, failureReason: failureReason)\r\n                        return .Failure(error)\r\n                    }\r\n                }\r\n                \r\n            } catch _ {\r\n                let failureReason = \"Network Error\"\r\n                let error = MTLError.errorWithCode(error!.code, failureReason: failureReason)\r\n                return .Failure(error)\r\n            }\r\n\r\n        }\r\n    }\r\n\r\n\r\npublic func responseObject<T: MTLModel> (\r\n                queue: dispatch_queue_t? = nil,\r\n                willStart: (() -> Void)? = nil,\r\n                didStop: (() -> Void)? = nil,\r\n                completionHandler: Response<T, NSError> -> Void) -> Self\r\n    {\r\n        willStart?()\r\n        UIApplication.sharedApplication().networkActivityIndicatorVisible = true\r\n        \r\n        return response(responseSerializer: Request.objectSerializer(), completionHandler: { (response: Response<T, NSError>) in\r\n            \r\n            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in\r\n                \r\n                self.printResponse(response)\r\n                \r\n                dispatch_async(queue ?? dispatch_get_main_queue()) {\r\n                    didStop?()\r\n                    UIApplication.sharedApplication().networkActivityIndicatorVisible = false\r\n                    completionHandler(response)\r\n                }\r\n                \r\n            })\r\n        })\r\n    }\r\n\r\n\r\nI have see #817 , but I  still don't know how to change my code. Please help me."}}