-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
I understand that the System.Text.Json is still in development. However, I would like to point out that the new deserializer produces very different results than the previous one.
Scenario:
public class MyRequest
{
public string ParamName { get; set; }
public object ParamValue { get; set; }
}Controller method:
[HttpPost]
public ActionResult<string> Post([FromBody] MyRequest myRequest)
{
return Content($"Type of '{myRequest.ParamName}' is {myRequest.ParamValue.GetType()}; value is {myRequest.ParamValue}");
}Posting this json:
{
"ParamName": "Bool param",
"ParamValue": false
}In .net core 2.1, the false value deserializes as boolean:
Type of 'Bool param' is System.Boolean; value is False
However, in .net core 3.0 preview 6, the false value deserializes as System.Text.Json.JsonElement:
Type of 'Bool param' is System.Text.Json.JsonElement; value is False
Will there be any chance to make the new deserializer work the same as in 2.1?
Note: we declare the ParamValue as object, as in the real app the values are of several different types, and so far the deserializer handled all them for us without issues. In 3.0, all this functionality is broken.
Thanks.