ApiModel icon indicating copy to clipboard operation
ApiModel copied to clipboard

array of dictionaries JSON response

Open wainglaister opened this issue 9 years ago • 2 comments

Not sure if I'm doing something wrong, but I have a request whose response is a simple array of dictionaries and it fails to map. I have resolved this by adding a line to ApiForm.swift (line 286):

if let arrayData = data as? [AnyObject] { return arrayData }

but I'm not sure if this is correct. Without this it's always trying to handle the response as a dictionary so it fails out.

wainglaister avatar Feb 04 '16 13:02 wainglaister

Excellent find! Do you think you could make a pull request with this? I can help you by writing a test when it's up.

erkie avatar Apr 05 '16 20:04 erkie

I made quite a few changes while playing around to see how much i liked realm. You made some other similar changes around the same time but implemented in a different way and I didn't spend time to resolve the conflicts. Since then I haven't been using realm at all, hence no PR. This specific change is literally:

private class func arrayFromResponseForNamespace(data: AnyObject, namespace: String) -> [AnyObject]? {
    if let arrayData = data as? [AnyObject] { return arrayData }
    return (data[namespace] as? [AnyObject]) ?? (data[namespace.pluralize()] as? [AnyObject])
}

(I made other changes related to response status codes, foreign key model transform + tests, ISO8601 date transform formats + tests that I can tell you about if you're interested)

wainglaister avatar Apr 07 '16 08:04 wainglaister