Aspnetcore: Blazor GetJsonAsync returns an empty object

Created on 12 Jun 2019  路  5Comments  路  Source: dotnet/aspnetcore

In version 3.0.0-preview6.19307.2 the GetJsonAsync extension method returns an empty object

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core '3.0.0-preview6.19307.2'
  2. Run this code var response = await _httpClient.GetJsonAsync<SomeComplexeGenericType<SomeType>>("http://api")
  3. See error
    The object return is empty

Expected behavior

Before version '3.0.0-preview6.19307.2' the object was successfully deserialized

Additional context

I can workaround with :

var message = await _client.GetAsync("http://api");
var content = await message.Content.ReadAsStringAsync();
var response = JsonSerializer.Parse<SomeComplexeGenericType<SomeType>>(content);
Done area-blazor bug

Most helpful comment

The JsonSerializer is case insensitive here and assumes camel case. We should change it to be case insensitive for deserialization. cc @rynowak

All 5 comments

The JsonSerializer is case insensitive here and assumes camel case. We should change it to be case insensitive for deserialization. cc @rynowak

This is already fixed!

How do I get this fix for all my calls? Do I need to wait till preview 7?

Yes @tsmccartan. this will be part of preview 7 release.

@tsmccartan You, can also add `[JsonPropertyName("Id")] to all properties in serializable class, this can help with solving issue now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glennc picture glennc  路  117Comments

rmarinho picture rmarinho  路  78Comments

radenkozec picture radenkozec  路  114Comments

mkArtakMSFT picture mkArtakMSFT  路  89Comments

KerolosMalak picture KerolosMalak  路  269Comments