Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationship object not deserialized #17

Open
Thiryn opened this issue May 4, 2018 · 8 comments
Open

Relationship object not deserialized #17

Thiryn opened this issue May 4, 2018 · 8 comments
Labels
bug Something isn't working

Comments

@Thiryn
Copy link

Thiryn commented May 4, 2018

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.

@aronbalog aronbalog added the bug Something isn't working label May 7, 2018
@ZahraAsgharzadeh
Copy link

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
Copy link
Author

Thiryn commented May 9, 2019

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
Copy link

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

@Thiryn
Copy link
Author

Thiryn commented May 9, 2019

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
Copy link

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

@Thiryn
Copy link
Author

Thiryn commented May 9, 2019

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
Copy link

Ok thanks for your help friend :)

@ZahraAsgharzadeh
Copy link

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants