[FEATURE] Support for custom JsonSerializerOptions
See original GitHub issueIs your feature request related to a problem? Please describe. I am trying to switch to the new library 8.x, but it does not seem it allows for custom format for Json serialization.
E.g. I need to add a date format, enum conversion, camel case, etc.
Before it was possible to do this:
var connectionSettings = new ConnectionSettings(pool, (serializer, values) =>
{
return new JsonNetSerializer(serializer, values, () => MySettings);
}
I did not find anything on how to do it in 8.x.
Describe the solution you’d like I want a possibility to provide my own options. If required it should be merged with DefaultRequestResponseSerializer if it has some options that have to be present.
Describe alternatives you’ve considered It seems it is possible to get to the Options of the default serialiezr like that:
var jsonSerializerOptions = ((SystemTextJsonSerializer) client.RequestResponseSerializer).Options;
I am not sure if it is intended, but it is not possible to replace the options completely, but possible to augment them. It seems a bit strange way of accessing the options and looks more like a side effect than a feature.
Issue Analytics
- State:
- Created 7 months ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top GitHub Comments
Hi, @ilya-scale. We don’t currently have a good story for augmenting the existing options. That hook you found won’t work for this scenario and shouldn’t be exposed publicly. Right now, you’d have to implement a custom
Serializer
and new it up in theElasticsearchClientSettings
by providing aSourceSerializerFactory
. However, you’d not get the built-in converters, so you may hit issues if you use any of our types on your POCO class for the source data.I have a roadmap item to refine the experience to make it easier to configure
JsonSerializerOptions
in some form.You’re welcome @KoalaBear84. Hopefully, this has all the capabilities you need and the new docs cover common scenarios.