graphql-dotnet / graphql-dotnet/graphql-client
SystemTextJsonSerializer causes unexpected behavior on serialization
- Dominant language
- C#
- Stars
- 648
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
When initializing SystemTextJsonSerializer with a custom JsonSerializerOptions, it messes the options in ways that are very difficult to predict and very difficult to debug.
I am using .Net 5
I believe that SystemTextJsonSerializer should take the JsonSerializerOptions as is and not try to modify it. For example, passing the options below cause some very weird results:
```
JsonSerializerOptions options = new JsonSerializerOptions(JsonSerializerDefaults.Web);
options.Converters.Add(new JsonStringEnumConverter()); //This causes wrong text conversion
options.Converters.Add(new DateTimeConverter()); //This is a custom converter I have for ISO Dates, haven't tested this one
options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; //This is ignored
```
Example of serialization:
```
public enum Salutation {
mr = 1, ms = 2
}
public class Sample {
public Salutation salutation { get; set; }
public string? optionalField { get; set; }
}
```
Results
> With System.Text.JsonSerializer directly:
```
{
"salutation": "mr"
}
```
> With SystemTextJsonSerializer from GraphQLClient:
```
{
"salutation": "MR",
"optionalField": null
}
```
At the moment I have some ugly workarounds. But that's far from ideal and error prone. Is there any way to simply take the options I provide without doing anything to it?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.