Circular relationships involving the `data` resource not being resolved properly during deserialization
Hi @jasminb! I'm seeing an issue with circular relationships, perhaps similar to https://github.com/jasminb/jsonapi-converter/issues/100, but regarding deserialization. Given models like:
@Type("user")
public class User {
@Id
public String id;
public String name;
@Relationship("campaign")
public Campaign campaign;
}
@Type("campaign")
public class Campaign {
@Id
public String id;
public String title;
@Relationship("owner")
public User owner;
}
and the following JSON from my API request:
{
"data": {
"attributes": {
"name": "Cassidy"
},
"id": "123",
"relationships": {
"campaign": {
"data": {
"id": "456",
"type": "campaign"
}
}
},
"type": "user"
},
"included": [
{
"attributes": {
"title": "My Campaign"
},
"id": "456",
"relationships": {
"owner": {
"data": {
"id": "123",
"type": "user"
}
}
},
"type": "campaign"
}
]
}
When I execute the following:
User user = new ResourceConverter(BuildConfig.API_BASE_URL, User.class, Campaign.class)
.readDocument(json.getBytes(), User.class)
.get();
I end up with user.campaign.owner being an empty object (only the id field is populated). I would expect user == user.campaign.owner to be true in this case, but they are actually separate objects when I check them in the debugger.
However, this issue only appears to happen when the data resource is part of the circular relationship. If there is a circular relationship amongst the included resources, the deserialization handles this well and works perfectly (i.e. user.campaign.owner is populated with all fields, and is actually the same object in memory as user).
Thanks for the help! Hopefully I'm just doing something silly that can resolve this issue. Just started using the library this week and am loving the ease of use so far.
Hey,
Thanks for reporting and providing steps to reproduce. Will take a look and fix it.
@jasminb Any update on this? Any way I can be helpful?
Hey @crcsaenz,
Will try to fix it soon, its not a simple fix due to how caching/parsing is done.
@jasminb I've submitted a pull request that fixes this issue #129