Setting Blazor Server Application JsonSerializerOptions

Viewed 656

When you have an MVC application you can append services.AddMvc().AddJsonOptions(options => ... and that will set the Json options for all the controllers.

What is the equivalent for a Blazor Server App? I tried services.AddRazorPages().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNameCaseInsensitive = true); and while the compiler didn't complain it didn't seem to have the desired effect and i still have to do the following to deserialize correctly:

var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var list = await JsonSerializer.DeserializeAsync<IEnumerable<CustomerSearchResultDto>>(await response.Content.ReadAsStreamAsync(), options);

Any ideas? Thanks in advance.

0 Answers
Related