We are trying to migrate some old .net framework projects to .net 6. The old .net projects use newton Json to deserialize or serialize and we found some behaviour differences in System.Text.Json.
For example, for this object:
{
"Codes": [
{
"Code": "HE37",
"InstrType": "F",
"PriceType": 2
},
{
"Code": "M996200",
"InstrType": "N",
"FundCiticode": "N2J8"
}
],
"SeriesTypes": [
1,
2
],
"Span": 8,
"Period": "Weekly",
"Shortest": "true",
}
Period is an Enum, in newton Json, we can provide either string or value (e.g. 2). Looks like we will need JsonStringEnumConverter to walk around this.
JsonSerializerOptions options = new JsonSerializerOptions
{
Converters = {
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
}
};
"Shortest" is a bool, in newton Json, we can provide a string "true" or bool true. In System.Text.Json, it will throw exception if a string "true" is provided.
It will be quite a lot of hassle if we change the behaviour of our system (as various external consumers already send bool value as a string). Is there a way to make System.Text.Json accept string boolean?