wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
264 stars 109 forks source link

How can we deserialize meta? #113

Closed aleufms closed 7 years ago

aleufms commented 7 years ago

I'm using only the deserialize function of the class Serialize (deserializeData). The "meta" on response is not setting the resource's meta parameter. My response is like that:

{"data":{"id":"4","type":"permalinks","attributes":{"slug":"ciencias-da-saude"}},"meta":{"entities":[{"id":5,"name":"Ciências da Saúde","slug":"ciencias-da-saude","description":null,"objective":null,"image":{"url":null},"color":null,"created-by":null,"updated-by":null,"node-type":"education_segment","suggested-to":"category","pre-requisite":null,"children":[{"id":60,"name":"Histologia Humana","slug":"histologia-humana"},{"id":61,"name":"Anatomia Humana Básica","slug":"anatomia-humana-basica"},{"id":62,"name":"Genética Humana","slug":"genetica-humana"},{"id":63,"name":"Biofísica","slug":"biofisica"},{"id":64,"name":"Farmacologia","slug":"farmacologia"},{"id":65,"name":"Bioquímica","slug":"bioquimica"},{"id":66,"name":"Biologia Molecular","slug":"biologia-molecular"}],"node-module-count":39,"entity-type":"node","node-modules":[],"media":[]}]}}

The attributes is getting mapped (in this case, only slug string) as the id and type, but the meta is always nil. Is there another way to extract/map it?

Thanks

aleufms commented 7 years ago

The jsonAPIObject have the meta information, but the jsonAPIOjbect.data, meta is always nil.

let jsonAPIObject = try NewAPIClient.jsonAPISerializer.deserializeData(response.data)

if let mappedObject = jsonAPIObject.data?.first as? T{
    return Observable.just(mappedObject)
}