0

I have a .NETCore Console App and I am serializing/deserializing using the following option

var serializeOptions = new JsonSerializerOptions
                    {
                        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                        WriteIndented = true
                    };

Is there any way that I can inject services.AddJsonOptions() and use Json.Text.Serializer without passing all the time my serializeOptions? Do I need to create my own SerializerWrapper for this?

Zinov
  • 3,817
  • 5
  • 36
  • 70
  • 3
    Does this answer your question? [How to globally set default options for System.Text.Json.JsonSerializer?](https://stackoverflow.com/questions/58331479/how-to-globally-set-default-options-for-system-text-json-jsonserializer) or - "If you use JsonSerializerOptions repeatedly with the same options, don't create a new JsonSerializerOptions instance each time you use it. Reuse the same instance for every call. " - [system-text-json-configure-options](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-configure-options?pivots=dotnet-6-0) – Ryan Wilson Apr 05 '22 at 20:16
  • kind of, the thing is that most of these solutions are for web apps :( and the other one is to create your own wrapper as an extension method – Zinov Apr 05 '22 at 20:25
  • mine is a console app – Zinov Apr 05 '22 at 20:57
  • Are you using a `Host`? You can configure services in a console app the same way. – ChiefTwoPencils Apr 05 '22 at 22:23

0 Answers0