-
Notifications
You must be signed in to change notification settings - Fork 6
Null value handling without using ExpandoObject #2
Comments
So there has been an update. I tried getting the IJSRuntime to use Json.Net. Since this didn't work I have asked on StackOverflow and done further research. I have asked the asp.net team about it and they say they won't allow users to change the serializer that |
UPDATE: Since it (very unfortunately) won't be supported in IJSRuntime I reached out to the corefx team to see what's going on in the development for System.Text.Json (potential support for a way to work around this issue. E.g. similar functionality like JsonObject from Newtonsoft.Json). These are the (currently) relevant links: |
Update: I have created a repos for the test-project I use to see how certain values are serialized. It's very helpful for solving this issue. You can find the repository here. |
Is migrated to mariusmuntean/ChartJs.Blazor#39 now. Do you want to provide the details in there as well @Joelius300? |
Here is the reason we need this in the first place described (chartJs doesn't ignore null values and it can't handle them).
See this question for detailed insight on how it's currently done. In the discussion with t3chb0t is some additional infos and links.
Here are the SerializerOptions you would use for the System.Text.Json serializer instead of json.net.
See this for how you can adapt to the change from json.net to System.Text.Json.
What's needed now?
public string Name { get; set; } = "Default-Name"
. If you were to have an instance of that class whereName = null
, you would get a json string whereName
is not present. If you then deserialize that back, you would getName = "Default-Name"
because it wasn't set to null. It wasn't set at all so the default value is used which is different from the value null which was expected. Workaround for that would be that every property with a nullable datatype must not have a default value. If this is incorrect, please correct me :)The text was updated successfully, but these errors were encountered: