tristanhimmelman / AlamofireObjectMapper

An Alamofire extension which converts JSON response data into swift objects using ObjectMapper
MIT License
2.66k stars 474 forks source link

Unable to map multi-dimensional array of JSON response which have key at first but no key in nested arrays with ObjectMapper+Alamofire #234

Open kokitang opened 6 years ago

kokitang commented 6 years ago

My JSON dictionary:

{"structure_model": [
        [
            [
                {
                    "test": "test"
                }
            ]
       ]
]}

My model:

class Component: Mappable, Codable {
    var test : String = ""
    required init?(map: Map) {

    }

    func mapping(map: Map) {
        test <- map["test"]
    }

}

class StructureModel: Mappable, Codable {

    var structureModels :    [Array<Array<Component>>]?

    required init?(map: Map){

    }

    func mapping(map: Map) {
        structureModels   <- map["structure_model"]
    }
}

What I did:

Alamofire.request(API, method: .post, parameters: parameters, encoding: JSONEncoding.default).validate().responseObject { (response: DataResponse<StructureModel>) in etc... }

What I expected:

Something like:

structureModels = [ 
  [
    [Component, Component, ...], 
    [Component, Component, ...],
    ...
  ] ,
  [ 
    [Component, Component, ...], 
    [Component, Component, ...], 
    ...
  ] ,
  ...]

What I got:

structureModels = nil