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

Error when batch forward geocoding a single query #1119

Closed
sduc opened this issue Feb 4, 2020 · 5 comments · Fixed by #1160
Closed

Error when batch forward geocoding a single query #1119

sduc opened this issue Feb 4, 2020 · 5 comments · Fixed by #1160
Assignees

Comments

@sduc
Copy link

sduc commented Feb 4, 2020

This seems to be similar to this issue on the swift repo: mapbox/MapboxGeocoder.swift#147

When trying to call enqueue batch call on a single query, the response will fail to be deserialized. For example when doing:

MapboxGeocoding client = MapboxGeocoding.builder()
    .accessToken(MAPBOX_ACCESS_TOKEN)
    .mode(GeocodingCriteria.MODE_PLACES_PERMANENT)
    .query("11 W 53rd St, New York, NY 10019, USA")
    .build();
client.enqueueBatchCall(new Callback<List<GeocodingResponse>>() {..});

The error I get when trying to batch call a single query is the following:

java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
    at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:80)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
    at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
    at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
    at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:122)
    at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:217)
    at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:116)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:216)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    ... 3 more

I believe the problem here is that

GET /geocoding/v5/{mode}/{query}.json

won't return a list when querying a single element which Gson will fail to deserialize.
It seems a list is only returned when more than one query is sent in {query}.

Note: this was tried on version 5.0.0

@SelaO
Copy link

SelaO commented Mar 3, 2020

Are there any updates with this?

@carefulAxe
Copy link

Also seeing this as well with version 5.1.0, exactly as described above. I tried with 4.9.0 and saw the same.

@moritzzzzz
Copy link

The Geocoding API only return a list of JSON object IF a batch request is sent, which is defined as a query with at least 1 semicolon in it.

The below workaround solves the problem for me. I have appended a semicolon at the end of my query, rendering it a batch request, for which the Geocoding API will return a list of JSON objects as response.

Adding a semicolon to the end of the query will make the Geocoding API return a list of JSON objects, which is the expected input for GSON.

MapboxGeocoding client = MapboxGeocoding.builder()
.accessToken(MAPBOX_ACCESS_TOKEN)
.mode(GeocodingCriteria.MODE_PLACES_PERMANENT)
.query("11 W 53rd St, New York, NY 10019, USA;")
.build();

@DzmitryFomchyn
Copy link
Contributor

Thanks for reporting the issue! It'll be fixed in the next SDK release.

@DzmitryFomchyn
Copy link
Contributor

SDK version 5.4.1 with the fix has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants