ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,165 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
ASP.NET 5 MVC Core application controller consumes json API using
using System.Text.Json;
public async Task<IActionResult> EstoAPICall()
{
...
EstoOst estoOst;
....
var json = JsonSerializer.Serialize(estoOst);
StringContent content = new(json, Encoding.UTF8, "application/json");
using var response = await httpClient.PostAsync("https://example.com", content);
}
public class EstoOst
{
public decimal Amount { get; set; }
}
This returns error response because caller requires lower case amount
but Serialize method returns upper case Amount
.
How to fix this ? Switching to Newtosoft or changing class property name to lowercase seems to be not good solutions.
The official documentation illustrates how to control casing. For example, camel casing.
How to customize property names and values with System.Text.Json