Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mwasif7 opened this issue May 12, 2024 · 5 comments
Closed
Labels

Comments

@mwasif7
Copy link

mwasif7 commented May 12, 2024

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

@mwasif7 mwasif7 added the bug label May 12, 2024
@mwasif7 mwasif7 changed the title GetJsonAsync<T> is not working after upgrading the library to version 4 >= GetJsonAsync<T> is not working after upgrading the Flurl Http to version 4 >= May 12, 2024
@tmenier
Copy link
Owner

tmenier commented May 15, 2024

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.

@njadhavparcelvision
Copy link

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

@alexandery
Copy link

alexandery commented Jun 19, 2024

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

@njadhavparcelvision
Copy link

Same approach we have used

@mwasif7
Copy link
Author

mwasif7 commented Jul 19, 2024

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

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

@mwasif7 mwasif7 closed this as completed Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants