1
votes

After upgrade to net core 3.0 with the new json serializer Objects with the [FromBody] tag are null;

controller api

[HttpPost("")]
[AllowAnonymous]
public async Task<JwtToken> Login([FromBody] UserCredentials userCredentials)
{
   ...
}

Startup config

public class Startup
{
   services.AddControllers();
   ...
}
public void Configure()
{
   app.UseEndpoints(endpoints => { endpoints.MapControllers().RequireAuthorization(); });
   ...
} 
public class UserCredentials
    {
        public string Password;
        public string Username;
    }
1
Have you fixed this issue? I also encounter the same issueHerman
Yes. add {get; set;} to the field to create properties.Thom Kiesewetter

1 Answers

0
votes

With Json.net serializer it was allowed to use fields. With the build in version of net core 3.0 the fields must be changed to properties.

public class UserCredentials
    {
        public string Password { get; set; }
        public string Username { get; set; }
    }