I have a webapi that receives a JSON through a POST. Sometimes one double value might arrive with null, so something like this
class A
{
public double val {get; set;}
}
Then the incoming json might be { "val": null }
I get a parsing error because null cannot be applied to double. In past days I would have added this
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
from the Newtonsoft library. However I'm using System.Text.Json nowadays. Is there something similar? I didn't find anything. At one place I use this here
[System.Text.Json.Serialization.JsonConverter(typeof(MyJsonConverter))]
But that seems to be an overkill for a single double value.
Btw: If possible I would like to avoid setting the double nullable, or else I would have to use .GetValueOrDefault()
at multiple places, which looks ugly