Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Null value handling without using ExpandoObject #2

@Joelius300

Description

@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?

  • Find out if there are CustomSerializers for System.Text.Json just like there are for json.net. If not, we cannot switch from json.net to System.Text.Json (because of the string and object enums) and have to explicitly instruct the app to use json.net in the startup (ConfigureServices). -> if there ever are (it looks like this jsonserializer stuff from .net is new in core 3 so they'll probably upgrade that) consider switching off json.net.
  • Find out if you can specify global serializer options (maybe this so question helps with that. This is however prior preview6 so we need to explicitly instruct the app to use json.net.)
  • Or just add the Attribute to the classes (you'd need that for almost every class which seems like pollution that's why there's the next point). See this so answer.
  • Determine which of the two above options is better. Maybe ask a SO question about this.
    • The first might have unexpected sideeffects when you'd have a class that gets deserialized with a property that has a default value. Say public string Name { get; set; } = "Default-Name". If you were to have an instance of that class where Name = null, you would get a json string where Name is not present. If you then deserialize that back, you would get Name = "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 second would require this attribute to be set for every single model class in the tree of config (which is a lot). I this worth it? Is this too polluted?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions