question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] Support for custom JsonSerializerOptions

See original GitHub issue

Is 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:closed
  • Created 7 months ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
stevejgordoncommented, Feb 20, 2023

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 the ElasticsearchClientSettings by providing a SourceSerializerFactory. 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.

1reaction
stevejgordoncommented, Mar 7, 2023

You’re welcome @KoalaBear84. Hopefully, this has all the capabilities you need and the new docs cover common scenarios.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to instantiate JsonSerializerOptions with System.Text. ...
In this article. Reuse JsonSerializerOptions instances; The JsonSerializerOptions.Default property; Copy JsonSerializerOptions; Web defaults for ...
Read more >
How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace.
Read more >
How to configure a default JsonSerializerOptions (System. ...
I have a custom configuration of JsonSerializerOptions that I want to be used automatically by my functions when de/serializing data. Question.
Read more >
Specifying JsonSerializerOptions in .NET 6 isolated Azure ...
I ran across the way to do it with an Azure Function. ... AddHttpClient(); // define your global custom JSON serializer options s....
Read more >
Using multiple JSON serialization settings in ASP.NET Core
Named JSON settings ... First, we need a way to specify multiple JSON serialization settings, and access these settings by name. Fortunately, ASP....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found