C#C
C#3y ago
4 replies
Hercules

❔ Troubleshooting JSON Mapping for POST Request to UserAsync Endpoint

I'm seeking guidance on formatting the JSON body for a POST request to the following API endpoint:

API Signature:

csharp
[HttpPost("CreateProjectUser")] 
public async Task<ActionResult> CreateProjectUserAsync(HikariUser projectUser, string userName) 


JSON Body (inputData):
{
    "projectUser": {
        "Username": "exampleProjectUser",
        "Email": "exampleProjectUser1@example.com",
        "Password": "Abc!123",
        "Role": "Contributor"
    },
    "userName": "AM" 
}


The issue I'm encountering is that "userName": "AM" is being incorrectly mapped to HikariUser projectUser.Username, when it should be filling the *exampleProjectUser *field. Additionally, the other properties of HikariUser are not being correctly populated and are showing as null.

I've already tried using [JsonPropertyName("")] attributes without success. Any guidance or solutions to ensure the correct mapping of JSON properties to the method parameters would be greatly appreciated.

 public class HikariUser
 {
     [JsonPropertyName("username")]
     public string UserName { get; set; }

     [JsonPropertyName("email")]
     public string Email { get; set; }

     [JsonPropertyName("password")]
     public string Password { get; set; }

     [JsonPropertyName("role")]
     public string Role { get; set; }
 }
Was this page helpful?