mapbox / mapbox/mapbox-java

Not able to parse response for optimization or direction API for .geometries("geojson")

Open
#1,373 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

jira-sync-complete
Dominant language
Java
Stars
438
Forks
117
PR merge metrics
No merged PRs in 30d

Description

if I add .geometries("geojson") as routeOption in
https://github.com/mapbox/mapbox-java/blob/main/samples/src/main/java/com/mapbox/samples/BasicDirections.java
or
https://github.com/mapbox/mapbox-java/blob/main/samples/src/main/java/com/mapbox/samples/BasicOptimization.java

It throws an error
Expected a string but was BEGIN_OBJECT at line 1 column 412 path $.trips[0].geometry

Where as it works when we call via API playground or use polyline6 as geometry.

Caused by: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 412 path $.trips[0].geometry
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:824) ~[gson-2.8.9.jar:na]
at com.google.gson.internal.bind.TypeAdapters$15.read(TypeAdapters.java:380) ~[gson-2.8.9.jar:na]
at com.google.gson.internal.bind.TypeAdapters$15.read(TypeAdapters.java:368) ~[gson-2.8.9.jar:na]
at com.mapbox.api.directions.v5.models.AutoValue_DirectionsRoute$GsonTypeAdapter.read(AutoValue_DirectionsRoute.java:223) ~[mapbox-sdk-directions-models-6.3.0.jar:na]
at com.mapbox.api.directions.v5.models.AutoValue_DirectionsRoute$GsonTypeAdapter.read(AutoValue_DirectionsRoute.java:31) ~[mapbox-sdk-directions-models-6.3.0.jar:na]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41) ~[gson-2.8.9.jar:na]
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82) ~[gson-2.8.9.jar:na]
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61) ~[gson-2.8.9.jar:na]
at com.mapbox.api.optimization.v1.models.AutoValue_OptimizationResponse$GsonTypeAdapter.read(AutoValue_OptimizationResponse.java:115) ~[mapbox-sdk-services-6.3.0.jar:na]
at com.mapbox.api.optimization.v1.models.AutoValue_OptimizationResponse$GsonTypeAdapter.read(AutoValue_OptimizationResponse.java:28) ~[mapbox-sdk-services-6.3.0.jar:na]

I am using mapbox-sdk-core-6.3.0.jar

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with samples/src/main/java/com/mapbox/samples/BasicDirections.java and BasicOptimization.java, reproduce the failure using geometries("geojson"), and inspect the response at trips[0].geometry. Compare the object returned for GeoJSON with the string returned for polyline6; done means both Directions and Optimization responses parse without the Gson exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.