You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
JsonSerializerOptions.Default = options;
2
This configuration doesn't work
3
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
System.Text.Json.JsonSerializer.Serialize(object, option);
It has to be set up this way for it to work, it's a bit too much of a pain to pass a configuration item each time you serialize it
The text was updated successfully, but these errors were encountered:
I would also like to know how to configure this globally. In Azure Functions before .NET 8 this used to work just fine:
// Setting global System.Text.Json.JsonSerializerOptions
services.Configure<JsonSerializerOptions>(options =>
{
options.PropertyNameCaseInsensitive = true;
options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault; // Property is ignored if its value is null. This is applied only to reference-type properties and fields.
});
After playing around a little i found it. .net 8 seems to have changed where you configure json options from. In addition to the .AddControllers().AddJsonOptions method which is still required for parsing request enums from strings, you should now use the ConfigureHttpJsonOptions method for parsing response enums to strings.
1
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
JsonSerializerOptions.Default = options;
2
This configuration doesn't work
3
System.Text.Json.JsonSerializer.Serialize(object, option);
It has to be set up this way for it to work, it's a bit too much of a pain to pass a configuration item each time you serialize it
The text was updated successfully, but these errors were encountered: