tristanhimmelman/AlamofireObjectMapper

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

Opened this issue · 0 comments

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