Deserialization does not work on repeated included relationships
See original GitHub issueIf there are relationships that share resources, and are included only once each (see the example below - there are only two books but one is both a “selling” and a “favorite”) when they are deserialized the second instance of the repeated relationship is not properly included (it just places null)
{
"data": {
"type": "user",
"id": "5ad2601522c6f6733408ae1f",
"attributes": {...},
"relationships": {
"favorite": {
"data": [
{
"type": "book",
"id": "5aca58621d13177065279691"
}
]
},
"selling": {
"data": [
{
"type": "book",
"id": "5ac8dd784f904b5a281aa061"
},
{
"type": "book",
"id": "5aca58621d13177065279691"
}
]
}
}
},
"included": [
{
"type": "book",
"id": "5aca58621d13177065279691",
"attributes": {...},
},
{
"type": "book",
"id": "5ac8dd784f904b5a281aa061",
"attributes": {...}
}
]
}
When deserialized, this returns
{
...
"id": "5ad2601522c6f6733408ae1f",
"selling": [
{
...
"id": "5ac8dd784f904b5a281aa061"
},
null <-- Relationship was included but presumably used up for something else!
],
"favorite": [
{
...
"id": "5aca58621d13177065279691"
}
]
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:5 (2 by maintainers)
Top Results From Across the Web
how to deserialize one to many relationship with both eager ...
When I query for product, I want product with ProductGroup (ProductGroup should not serialize again the products inside) ...
Read more >Jackson - Bidirectional Relationships - Baeldung
First, we'll discuss the Jackson JSON infinite recursion problem. Then we'll see how to serialize entities with bidirectional relationships.
Read more >Bulletproof Interface Deserialization in Json.NET
NET provides a simple setting to solve the problem of deserializing a property that is an interface with multiple implementing classes:
Read more >[C #] Some scenarios for deserializing a JSON to a type with ...
Recently I feel that using the System.Text.Json library for serializing/deserializing with JSON is increasing in C# programming.
Read more >pickle — Python object serialization — Python 3.11.1 ...
Object sharing happens when there are multiple references to the same object in ... Unlike pickle, deserializing untrusted JSON does not in itself...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is a known issue with this repo but the author hasn’t done anything to publicly address it. I forked this repo to fix this issue. You can view the PR here: https://github.com/SeyZ/jsonapi-serializer/pull/170
And you can view my fork here: https://github.com/AELSchauer/jsonapi-serializer
Can confirm. Just spent ~6 hours figuring this out + 2 hours on adapting solution by @AELSchauer (thanks a lot!). Glad this issue was already pointed out or I’d have to spend even more time thinking I’ve gone mad 😄
Basically, having circular dependencies on your resources is not possible due to references evaluated as
null
.A simple example would be the following JSONAPI response:
https://github.com/SeyZ/jsonapi-serializer/commit/4e7001663493e124040de228349e1ac4e6ba0890 without a patch produces following result:
Demonstration available here.