tmenier / Flurl

Fluent URL builder and testable HTTP client for .NET

Home Page:https://flurl.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GetJsonAsync<T> is not working after upgrading the Flurl Http to version 4 >=

mwasif7 opened this issue · comments

I have recently upgraded my Flurl Http from 3.2.4 to 4.0.2.
Post upgrading, my test cases start failing when deserializing it to a type. I have also verified the issues while running the app locally.

To check the deserialization issue, I have explicitly deserialized the Json to a given type using JsonConvert.Deserializer() which works perfectly.
When I downgrade the version to 3.2.4 everything starts working normally.

  • Even I have installed Flurl.Http.Newtonsoft but with no success.

Can someone please verify the issue? Thanks

Package versioning:
Flurl: 4.0.0
Flurl.Http: 4.0.2

Please provide a minimal example of something that won't deserialize as it did in 3.x. Using Flurl.Http.Newtonsoft should absolutely be the key to it working exactly the same.

Same issue I am also facing. Everything is working fine version 3.2.4 but when we upgrade it stops deserializing using GetJson method. It happening only when we use PostJsonAsync() method. Working fine for PostUrlEncodedAsync() method. Seems to me issue with the response from PostJsonAsync

I was seeing the same issue with .GetJsonAsync(). JSON returned from an odata endpoint doesn't get de-serialized correctly.

Calling code:

var odataResult = await "https://domain.com"
    .AppendPathSegment("/odata/Entities")
    .WithOAuthBearerToken("token-value")
    .GetJsonAsync<OdataResponse<MyDTO>>();

private class OdataResponse<T>
{
    public IEnumerable<T> value;
}

private class MyDTO
{
    [Key]
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Route { get; set; }
    public bool Default { get; set; }
    public string Metadata { get; set; }
}

Changing code to use Flurl.Http.Newtonsoft helps with this issue:

var odataResult = await "https://domain.com"
    .AppendPathSegment("/odata/Entities")
    .WithOAuthBearerToken("token-value")
    .WithSettings(settings => 
      { 
        settings.JsonSerializer = new NewtonsoftJsonSerializer(); 
      }
    )
    .GetJsonAsync<OdataResponse<MyDTO>>();

Response returned by the odata endpoint:

{
    "@odata.context": "http://domain.com/odata/$metadata#Entities",
    "value": [
        {
            "Id": "d1ebc584-038a-4dbd-f06c-08dc8fbf81d1",
            "Name": "My second entity",
            "Route": "werthjk",
            "Default": false,
            "Metadata": "{\"name\":\"My second entity\",\"route\":\"werthjk\",\"description\":\"Testing creation\",\"default\":false,\"extras\":\"[]\"}"
        }
    ]
}

Package versioning:
Flurl: 4.0.0
Flurl.Http: 4.0.2

Same approach we have used

I have used the below code in DI to get it to work again:

FlurlHttp.Clients.WithDefaults(builder =>
{
builder.UseNewtonsoft();
});