Skip to content

[Blazor Webassembly] Give JsonSerializerOptions to HttpClient Make result "empty" #21322

Closed
@julienGrd

Description

@julienGrd

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

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions