Setting Blazor Server Application JsonSerializerOptions
Asked Answered
B

0

6

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.

Blunderbuss answered 11/5, 2020 at 20:36 Comment(2)
Did you ever find out?Tonita
There appears to be an open issue for this github.com/dotnet/aspnetcore/issues/26000, in my current project we've just created a service for all JSON formatting. We handle the options from there to make it uniformSandy

© 2022 - 2024 — McMap. All rights reserved.