79604099

Date: 2025-05-02 20:57:28
Score: 1
Natty:
Report link

I am using a singleton with dependency injection to get the default settings I want everywhere:

services.AddSingleton(new JsonSerializerOptions()
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    PropertyNameCaseInsensitive = true,
    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
});

And then it is available anywhere like so:

public class MyClass(JsonSerializerOptions jsonOpts)

Not sure if this is the best solution - hopefully I never have to change this, as that would warrant a potentially massive regression test.

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Matthew Beck