Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Failed to serialize Requestable Model #14

Closed
ttuygun opened this issue Dec 8, 2016 · 3 comments
Closed

Failed to serialize Requestable Model #14

ttuygun opened this issue Dec 8, 2016 · 3 comments

Comments

@ttuygun
Copy link

ttuygun commented Dec 8, 2016

fatal error: ResponseSerializer failed to serialize the response to Requestable Model of type Dictionary<String, Any>:Restofire/Sources/AlamofireUtils.swift, line 110

I took this error in JSON starts and ends with "[]" like arrays. g.e.
[ {
"name": ""
},
{
"name":""
}]

but it works perfectly in "{}" response. g.e.
{
"name":""
}

Is this problem related with Restofire or Alamofire?

edit: I tested with Alamofire's standart API, it works perfectly. I think the problem related with Restofire's itself. I sent email as complete response that fails to serialize.

@rahul0x24
Copy link
Member

Can you also paste the Requestable class you have written to construct this service ?

@ttuygun
Copy link
Author

ttuygun commented Dec 8, 2016

protocol HaberConfigurable: Configurable { }

extension HaberConfigurable {

    var configuration: Configuration {
        var config = Configuration()
        config.baseURL = "https://api.***/v1/"
        config.headers = ["apikey": “***”]
        config.logging = Restofire.defaultConfiguration.logging
        return config
    }
}

protocol HaberValidatable: Validatable { }

extension HaberValidatable {

    var validation: Validation {
        var validation = Validation()
        validation.acceptableStatusCodes = Array(200..<300)
        validation.acceptableContentTypes = ["application/json"]
        return validation
    }
}

protocol HaberRetryable: Retryable { }

extension HaberRetryable {

    var retry: Retry {
        var retry = Retry()
        retry.retryErrorCodes = [.timedOut, .networkConnectionLost]
        retry.retryInterval = 20
        retry.maxRetryAttempts = 10
        return retry
    }
}

struct HaberGETService: Requestable, HaberConfigurable, HaberValidatable, HaberRetryable {

    typealias Model = [String: Any]
    var path = String()
    let encoding: ParameterEncoding = URLEncoding.default
    var parameters: Any?

    init(path: String, parameters: Any?) {
        self.path = path
        self.parameters = parameters
    }
}

@ttuygun ttuygun closed this as completed Dec 8, 2016
@ttuygun ttuygun reopened this Dec 8, 2016
@rahul0x24
Copy link
Member

If your api returns an Array. You need to use Array of Dictionary as your ResponseModel

typealias Model = [[String: Any]]

@ttuygun ttuygun closed this as completed Dec 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants