aveine/JsonAPI

Deserialization of Included fails on Class that's inherited

Closed this issue · 2 comments

Nice package.

I've encountered a deserialization problem in a certain case.

Adding an example to your TestClasses, given the following

class Person: Resource {
    var name: String?
    var favoriteArticle: Article?
    override class var resourceType: String {
        "persons"
    }
}

class Contact: Person {
 var email: String?
  override class var resourceType: String {
    "contacts"
  }
}

class ContactList: Resource {
  var name: String?
  var contacts: [Contact]?
  override class var resourceType: String {
    "contactlists"
  }
}

a fetch on contactlists that has "included" contacts will fail to populate. ResourceManager expects the resource classes to inherit directly from Resource.

I'll submit a PR that has new failing tests in one commit, followed by a proposed fix in the following commit.

Hello !

Thanks for finding the issue, indeed this is something we didn't encounter while using it since we don't have this kind of usage.

I'm gonna review the PR and deploy the fix version on CocoaPods once it has been merged.

Thanks for merging so quickly!