Hi,
I am testing the java client for the directions API, more precisely the matrixPost.
The problem I have is related to the from_points
and to_points
fields. Both of them are supposed to be passed as a List<List<Double>>
on the Json request body. However, when using the Java client, the methods MatrixRequest.fromPoints
and MatrixRequest.toPoints
get a String as argument, and the fields are then serialized as Strings.
So, when I execute a matrix post request with this code:
MatrixRequest request = new MatrixRequest()
.points(null)
.fromPoints("[[2.311129,48.844055], [2.351729,48.836792], [2.366178,48.884376]]")
.toPoints("[[2.325425,48.896827], [2.212104,48.893765]]")
.outArrays(Arrays.asList("times", "distances"))
.vehicle("car");
MatrixResponse response = apiInstance.matrixPost(API_KEY, request);
Then the posted request body is the following:
{
"from_points": "[[2.311129,48.844055], [2.351729,48.836792], [2.366178,48.884376]]",
"to_points": "[[2.325425,48.896827], [2.212104,48.893765]]",
"out_arrays": ["times", "distances"],
"vehicle": "car"
}
This is obviously not correctly handled by the server and ends up whit a ‘Server Error’ api exception:
Exception in thread "main" com.graphhopper.directions.api.client.ApiException: Server Error
at com.graphhopper.directions.api.client.ApiClient.handleResponse(ApiClient.java:1047)
at com.graphhopper.directions.api.client.ApiClient.execute(ApiClient.java:970)
at com.graphhopper.directions.api.client.api.MatrixApi.matrixPostWithHttpInfo(MatrixApi.java:289)
at com.graphhopper.directions.api.client.api.MatrixApi.matrixPost(MatrixApi.java:274)
at com.praxedo.executables.forecast.ghdirectionsapi.DirectionsApi.main(DirectionsApi.java:22)
The expected request body should be like this:
{
"out_arrays": [
"distances",
"times"
],
"from_points": [
[
2.311129,
48.844055
],
[
2.351729,
48.836792
],
[
2.366178,
48.884376
]
],
"to_points": [
[
2.325425,
48.896827
],
[
2.212104,
48.893765
]
],
"vehicle": "car"
}
So my question is: why the methods MatrixRequest.fromPoints
and MatrixRequest.toPoints
receive a String and how should I use the Java client to post correct matrix requests?
Thanks in advance,
Jose