-
-
Notifications
You must be signed in to change notification settings - Fork 158
How to deserialize a class with a relationship that is a derived class? #696
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
Comments
Thanks for reporting this issue. There might be some issues with the (de)serialization of inherited properties, but to be sure what is going wrong and to see if we need to patch anything in the internals, we would need some more details. Preferably if you could open up a reproduction repository for us to step into and debug, or even better would be a PR with a few tests that reproduce the issue in the JsonApiExample project |
In this repository, you can see the issue Test example: |
Hi @marioGomezDev, The repro repository your provided targets JADNC v3, so I upgraded it to .NET Core 3.1 and JADNC 4-beta1. After that, I was able to reproduce your issue using the next request: POST https://localhost:44308/articles HTTP/1.1
{
"data": {
"type": "articles",
"attributes": {
"article-prop": "AP-new"
},
"relationships": {
"author": {
"data": {
"type": "students",
"id": "1"
}
}
}
}
} This crashes in the deserialization process, because it tries to create an instance of abstract Person class. Instead it should look at the actual type ("students" in this case) and so create an instance of Student. I have a preliminary fix at #828. For context, the next request shows the sample data: GET https://localhost:44308/articles?include=author HTTP/1.1 {
"links": {
"self": "https://localhost:44308/articles?include=author"
},
"data": [
{
"type": "articles",
"id": "1",
"attributes": {
"article-prop": "ArticleProp 1"
},
"relationships": {
"author": {
"links": {
"self": "https://localhost:44308/articles/1/relationships/author",
"related": "https://localhost:44308/articles/1/author"
},
"data": {
"type": "students",
"id": "1"
}
}
},
"links": {
"self": "https://localhost:44308/articles/1"
}
},
{
"type": "articles",
"id": "2",
"attributes": {
"article-prop": "ArticleProp 2"
},
"relationships": {
"author": {
"links": {
"self": "https://localhost:44308/articles/2/relationships/author",
"related": "https://localhost:44308/articles/2/author"
},
"data": {
"type": "teachers",
"id": "2"
}
}
},
"links": {
"self": "https://localhost:44308/articles/2"
}
}
],
"included": [
{
"type": "students",
"id": "1",
"attributes": {
"student-prop": "StudentProp 1",
"person-prop": "PersonProp Student 1"
},
"links": {
"self": "https://localhost:44308/students/1"
}
},
{
"type": "teachers",
"id": "2",
"attributes": {
"teacher-prop": "TeacherProp 2",
"person-prop": "PersonProp Teacher 1"
},
"links": {
"self": "https://localhost:44308/teachers/2"
}
}
]
} |
Description
My domain are set up like this:
When I post an Article, it fails to deserialize the specific Teacher or Student class, how can I fix it?
...
Environment
The text was updated successfully, but these errors were encountered: