aronbalog / Vox

Swift JSON:API client framework
http://jsonapi.org
MIT License
46 stars 19 forks source link

Relationship object not deserialized #17

Open Thiryn opened 6 years ago

Thiryn commented 6 years ago

If you try to deserialize an object such as

  "data": {
      "attributes": {
        "name": "John Doe",
        "age": null,
        "gender": "male"
      },
      "type": "persons",
      "id": "id-1",
      "relationships": {
        "favoriteArticle": {
          "data": {
            "id": "article-identifier",
            "type": "articles"
          }
        }
      }
    }

when trying to get person.favoritArticle.id you are getting "" because When fetching the attribute, the relationship is properly found and the Context tries to get the relationship In Context_Query but the ResourcePool has no knowledge of a favoriteArticle with the ID article-identifier, the the value is null... I think it should be a nice feature to add the objects in the resourcePool either at the deserialization or even bette when a relationship exists and the object is not found, creating it.

ZahraAsgharzadeh commented 5 years ago

Hi, I have the same problem in deserializing objects that have relationships ... I didn't understand clear what you offered to do to fix this issue . Could you please explain it to me more clear ?! This issue is driving me crazy 🤦🏻‍♀️

Thiryn commented 5 years ago

By the look of it, this library is not maintained. I do not recommend to use it. This problem is one of the many I noticed when first using this library. None of it has been addressed, I made changes to a private copy of the library when I was using it. Unfortunately, I do not have it anymore and can not share the fix I had for this particular bug. This library is a good start of what could have been a nice parsing/loading library but it is simply too bugged to be usable in a production environment.

ZahraAsgharzadeh commented 5 years ago

Nevertheless do you know any JSON API library to use instead of this ?!

Thiryn commented 5 years ago

Unfortunately, there is none I know of. I would recommend to use a generic JSON parsing library like SwiftyJSON and wrap it to enforce the JSON API specs. It is achievable but will need some time investment on your side. This would be the best way to implement such a thing. Forget about Vox, it will only make you lose time.

ZahraAsgharzadeh commented 5 years ago

Thanks guy, Didn't you work with Spine Library ? It supports JSON API .

Thiryn commented 5 years ago

I did not, I am no longer working with this environment (JSON API/iOS) and could not be of any more help, I gave you all I got ;)

ZahraAsgharzadeh commented 5 years ago

Ok thanks for your help friend :)

ZahraAsgharzadeh commented 4 years ago

Hi friend . Can you help me ? Do you know any way to write this function once, not every time ? cause I use it in all my project and it is not good to copy and paste all function every where I need . My mean is this code to make it short for use every where :

let client = JSONAPIClient.Alamofire(baseURL: baseURL)
let dataSource = DataSource<resourse>(strategy: .path("/path"), client: client)
do{
    try dataSource
        .fetch().include(["something"])
        .result({ (document: Document<[resourse]>) in
            let results = document.data

            // do some thing

        }) { (error) in
            // and do this every time
            if let error = error as? JSONAPIError {
                switch error {
                case .API( let errors):
                    ApiResponse(response: errors)
                default:()
                }
                return
            }else{
                ApiResponse(response: nil)
            }
    }
}catch let error_object{
    print(error_object)
}