-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Closed
Copy link
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyThis issue is related to and / or impacts Blazor WebAssembly
Description
Hello Guys,
It seem the new System.Text.Json Api can now handle ReferenceLoopHandling as suggest this issue (#21187 (comment)).
So i try implement this in my app to replace Newtonsoft.Json.
I precise i have this version of System.Net.Http.Json : 5.0.0-preview.3.20214.6
I configure my server project to activate this
pServices.AddMvc()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandling = ReferenceHandling.Preserve;
});
And my client project
JsonSerializerOptions options = new JsonSerializerOptions()
{
ReferenceHandling = ReferenceHandling.Preserve
};
var result = await sender.GetFromJsonAsync<T>(requestUrl, options);
I don't have errors, i retrieve an array with the correct amount of items, but all the properties are empty.
I notice is the same thing with an empty JsonSerializerOptions, so it seem not related to this specific option or to the server project.
To reproduce in the default project, just add an empty option :
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast", new System.Text.Json.JsonSerializerOptions());
//all the forecast here have theirs properties empty
Thanks !
Metadata
Metadata
Assignees
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyThis issue is related to and / or impacts Blazor WebAssembly