JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.82k stars 445 forks source link

Allow initial System.Text.Json.JsonSerializerOptions to be a copy from existing options #3206

Closed CptWesley closed 4 months ago

CptWesley commented 4 months ago

For most of our applications we are used to configuring a single JsonSerializerOptions instance that is reused everywhere. For consistency we would also like to use the same configuration for Marten, but currently it is not able to provide a JsonSerializerOptions instance that is used to configure the serializer, instead it is only possible to provide a configuration function.

My suggestion would be to introduce a new SystemTextJsonSerializer constructor that accepts a JsonSerializerOptions instance that is passed as argument to the constructors for _clean, _options, _optionsDeserialize and _withTypes. This ensures that the settings configured provided by this base JsonSerializerOptions are copied to the initial versions of the 4 internal options.

I'm not entirely sure if this is the cleanest solution, but it does the job of enabling us to provide a pre-configured JsonSerializerOptions instance.