I am posting below data to 2 different api endpoints, one we have in an ASP.NET Web API 2 application and while other I have in an ASP.NET Core 3.1 Web API application.
var data = new Data
{
Key = "k1",
Value = 80
};
IClient httpClient = new FluentClient("http://localhost:46551/");
var x = httpClient.PostAsync("weatherforecast", data).GetAwaiter().GetResult();
For both Web API applications, my model class is below where Value
is object
type and this is my hard requirement, I can't go with actual type.
public class Data
{
public string Key { get; set; }
public object Value { get; set; }
}
When I am posting data to ASP.NET Web API 2 (with .Net 4.6.1), the VS debugger shows only value correctly without any other payload:
But for ASP.NET Core 3.1 Web API, the VS debugger shows like this, totally different representation along with ValueKind
:
I have a requirement to write data
into Json format with below expected output,
{ "Key":"k1", "Value":80 }
While I am trying to serialize data
for the ASP.NET Core 3.1 Web API, I get this output:
var ser = JsonConvert.SerializeObject(data);
{ "Key":"k1", "Value": {"ValueKind":4} }
For the ASP.NET Web API 2 application, though I am getting expected output.
Question, how to get this output { "Key":"k1", "Value":80 }
from the ASP.NET Core 3.1 application and why there is a different behavior from both applications?
Thanks,