Posting JSONAPI data not binding
See original GitHub issueWhen I have the following classes:
public class ApplicationUserViewModel : Identifiable<string>
{
public ApplicationUserViewModel()
{
Id = Guid.NewGuid().ToString();
Roles = new List<ApplicationRoleViewModel>();
}
[NotMapped]
public string StringId { get => Id; set => Id = value; }
[Attr("username")] public string UserName { get; set; }
[Attr("email")] public string Email { get; set; }
[HasMany("roles")]
public List<ApplicationRoleViewModel> Roles
{
get;
set;
}
}
public class ApplicationRoleViewModel : Identifiable<string>
{
public ApplicationRoleViewModel()
{
Users = new List<ApplicationUserViewModel>();
Id = Guid.NewGuid().ToString();
}
[NotMapped]
public string StringId { get => Id; set => Id = value; }
[Attr("name")]
public string Name { get; set; }
[HasMany("users")]
public List<ApplicationUserViewModel> Users
{
get;
set;
}
}
And I post the following JSON
{
"data": {
"id": "461a2700-114b-4667-bacf-e4425d52354f",
"attributes": {
"email": "123@123.com"
},
"relationships": {
"roles": {
"data": [
{
"type": "roles",
"id": "67fd9442-9d8c-45de-bf42-4af8be9a8d40"
}
]
}
},
"type": "users"
}
}
It doesn’t deserialize properly and the model passed into the controller has empty properties.
Is there anything glaringly wrong here?
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (22 by maintainers)
Top Results From Across the Web
Why is my model not binding using a post with JSON in . ...
Your json format has a wrong structure so that model binding does not work, it should be just something like this:
Read more >NET 6 API unable to bind JSON to model on POST requests
I've been banging my head against a wall for two days trying to get an API method to bind a JSON request body...
Read more >Model binding JSON POSTs in ASP.NET Core
In this post, I am going to show what to do if you are converting a project to ASP.NET Core and you discover...
Read more >RequestBody is unable to bind (merge) JSON formatted ...
The issue is that Server side, when the JSON data sent is "bound" to the Command object instance, there is no way to...
Read more >Problem in binding when we send POST request ...
We are trying to send POST request and handle this request in controller behavior model binding with FromBody Attribute. And before binding if...
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 FreeTop 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
Top GitHub Comments
You can get the pre-release (2.2.2-alpha1-0075) using feed https://www.myget.org/F/research-institute/api/v3/index.json
Seems to be resolving my services :p
The error was mismatched package versions 😃
Get Outlook for iOShttps://aka.ms/o0ukef
From: Jared Nance notifications@github.com Sent: Thursday, April 5, 2018 7:09:28 PM To: json-api-dotnet/JsonApiDotNetCore Cc: Wayne Douglas; Author Subject: Re: [json-api-dotnet/JsonApiDotNetCore] Posting JSONAPI data not binding (#237)
I haven’t done any additional work that would solve this issue yet. However, this is a major item for me and I’d like to get it in the next release. I still need to do some design around this. It may not be easy to develop a fix in a non-breaking way.
Regarding your exception, that occurs at runtime? Can you provide the stack trace?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/json-api-dotnet/JsonApiDotNetCore/issues/237#issuecomment-379027119, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAK3jE6WkTTNeiHOQVdVeb6N6qYKnzwWks5tll3YgaJpZM4SWYH9.