ardalis / ardalis/Ardalis.ApiClient

Allow customization of JsonSerializerOptions

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
39
Forks
6
PR merge metrics
No merged PRs in 30d

Description

As a user of the API client library, I'd like to request the ability to customize the JsonSerializerOptions used for serialization and deserialization of JSON data. Currently, the JsonSerializerOptions are implemented within the HttpResponse class and cannot be modified or overridden by the library users. This limitation prevents us from using custom JsonConverterFactory instances, handling specific serialization scenarios, or applying custom naming policies.

Allowing customization of JsonSerializerOptions would provide users with greater flexibility and control over the JSON serialization process. This could be achieved by exposing the JsonSerializerOptions as a public property or through a method that allows users to provide their own JsonSerializerOptions instance.

Here is a potential solution:

1. Expose a public property or method in the library's main class to set the JsonSerializerOptions. For example:

```
public class ApiClient
{
public JsonSerializerOptions JsonSerializerOptions { get; set; } = new JsonSerializerOptions();

// ...
}
```

2. Use the JsonSerializerOptions provided by the user when calling JsonSerializer.Deserialize methods in the library.

This change would enable users to easily customize the JSON serialization process and handle various scenarios, such as:

- Using custom JsonConverterFactory instances to handle specific data types or scenarios.
- Applying custom naming policies (e.g., camelCase, snake_case) to match the API's conventions.
- Configuring other JsonSerializerOptions settings, such as handling null values or date formats.

I believe this improvement would make the library more flexible and user-friendly. Please consider implementing this feature in the next release of the API client library.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the HttpResponse class and the main ApiClient class to trace where JsonSerializer.Deserialize is called and where JsonSerializerOptions are created. Determine how a user-provided options instance should be exposed and used for both serialization and deserialization, then verify that custom converters and naming policies are honored across the API client.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.