I’m using @stukalov 's GitHub Statistics example project. I’ve created a new project and amended everything to fit my project, but it’s failing to load the external service correctly. It’s returning with the error code 410 “Gone”.
I have tested the necessary URL through a cURL call and have verified that it works correctly and returns relevant data (key changed here):
Seems something wrong with the generated URL. It would help to apply the BODY log level for your Retrofit client and see what exactly is generated. This article will help you to enable proper logging level: Retrofit 2 — Log Requests and Responses.
After setting up the logging I found that I set the base url as https://flightxml.flightaware.com/json/FlightXML2, and RetroFit required it to be https://flightxml.flightaware.com, so my final URL was missing the /json/FlightXML2 portion.
I’m wondering if you could provide a quick solution to parsing the returned results. It’s being returned as one object, so I’m getting the following error:
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
My results are returned as such:
I’m not 100% sure, but I think it’s trying to parse it in the following code:
List<Flight> flights = response.body();
if (Objects.requireNonNull(flights).size() == 0)
next = false;
else
result.addAll(flights);
I’m not sure the correct way to handle this in JAVA. Any help you can provide would be much appreciated.
I very well may be misunderstanding, but it seems from the error result that the result is already in object form, and is expecting an array list, or collection list. I hope I’m not confusing the issue.
So in that vein, I’m attempting to extract the “flights” portion of the returned result (above) and get it into an acceptable format of a List type. I’ve been playing around with a bunch of options, such as:
List<Flight> responseBody = response.body();
JSONObject flightObject = new JSONObject(responseBody);
List flightList = flightObject.getJSONArray("flights").toList();
List<Flight> flights = flightList;
if (Objects.requireNonNull(flights).size() == 0)
next = false;
else {
result.addAll(flights);
However, this just keeps giving me the same error. I’m banging my head on the keyboard trying to get this working. I appreciate any help.
From what I see you get a single object in return, which is FlightInfoResult, which in its turn includes a list of flights along with next_offset value. So, you should not expect List as the return type, but a single object, as I pointed above.