-
-
Notifications
You must be signed in to change notification settings - Fork 380
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() returns null when the response content is not JSON #292
Comments
If the shape of a successful (200) response is unknown ahead of time, I would suggest using If the expected shape differs only in error conditions (vast majority of cases where I've seen this come up), the try/catch pattern works well for this. |
What do you mean with "do the parsing yourself"? The problem is that a "manual" call to So what I'm saying is that when the deserialization returns null, the request should be considered as failed and an exception should be thrown by Flurl, because the response doesn't match the expected schema. Currently the problem is that after calling Is there something I'm missing that doesn't make this a possible solution? 😊 |
Can you provide an example of this? I've never seen that. |
I've found that I'm also pretty sure that there are other cases when deserialization returns null, but I can't reproduce anything now... I know that I've added a check for null in my application some days ago, because I was getting null sometimes. Also, if you search for "DeserializeObject returns null" there are other people talking about this. There's also a very recent issue report on the Newtonsoft.Json GitHub repo. |
You're right about random.org, I tried that and got the same result. Not sure if it's an anti-screen-scraping thing or what, but both the browser and Postman return HTML content, whereas HttpClient returns a completely empty body. There are 2 cases I know of where If you're suggesting that Flurl should throw on If you're suggesting there are other cases where you get null, where the body is neither empty nor |
I don't have any code that reproduces that situation right now. I don't actually remember how I got that result when I thought adding a null-check in my application was needed... |
If it's any consolation, #288 is a top priority for the next release. :) |
@tmenier that's great indeed, thank you 😉 |
It appears that when the content of a web page response is not a properly deserializable JSON, the
GetJsonAsync()
call returns null.This line reproduces the issue:
I expect the call to throw an exception in this case. The
GetJsonAsync
call should succeed only if the response content is actually a JSON payload.I believe this happens because Newtonsoft.Json is returning null when the input is not parsable, but that's a bit weird because it should throw instead of failing silently...
The text was updated successfully, but these errors were encountered: