Deserializer only links attributes and not included relationships
See original GitHub issueFor a simple model like below
public class Customer : Identifiable
{
[HasMany] public List<Order> Orders { get; set; }
}
public class Order : Identifiable
{
[HasMany] public List<Invoice> Invoices { get; set; }
}
public class Invoice : Identifiable { }
Serializer works fine and get customer with included relationship returns the desired response /api/v1/customers?included=orders.invoices
{
"data": {
"attributes": {},
"relationships": {
"orders": {
"links": {
"self": "https://localhost:44351/customers/1234/relationships/orders",
"related": "https://localhost:44351/customers/1234/orders"
},
"data": [
{
"type": "orders",
"id": "4567"
}
]
}
},
"type": "customers",
"id": "1234"
},
"included": [
{
"attributes": {},
"relationships": {
"invoices": {
"links": {
"self": "https://localhost:44351/orders/4567/relationships/invoices",
"related": "https://localhost:44351/orders/4567/invoices"
},
"data": [
{
"type": "invoices",
"id": "7890"
}
]
}
},
"type": "orders",
"id": "4567"
},
{
"attributes": {},
"type": "invoices",
"id": "7890"
}
]
}
However on using the same json as input for post/put operation and trying to deserialize into customer instance with all fields/relationships populated, it does not load included relationship. In this instance, customer has orders attributes populated but invoices is appearing blank.
Is it because we are only setting attributes and not relationship. Can we please modify it to add second level or more relationship be included as well. https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/9059560ffdaa9cc263fd352bb7dc1106255d6148/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs#L323
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
I totally agree, I’m in!
Work that will be involved:
JsonApiContext
, (in particular, I think, the exposure ofHttpContextAccessor
) so that we can decouple it from query params.JsonApiContext
are usedThis will surely involve breaking changes in the API. I hope I can make a proposal where to start on soon. If you feel like getting involved, we would greatly encourage that!
resolved in #558