# Problem in the Java API Matrix example on the documentation

**URL:** https://ask.openrouteservice.org/t/problem-in-the-java-api-matrix-example-on-the-documentation/1632
**Category:** openrouteservice
**Created:** [April 28, 2020, 8:46pm UTC](https://ask.openrouteservice.org/t/problem-in-the-java-api-matrix-example-on-the-documentation/1632 "2020-04-28T20:46:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Pedro\_Pereira](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/pedro_pereira/32/508_2.png) [@Pedro\_Pereira](https://ask.openrouteservice.org/u/Pedro_Pereira)
#### Post date: [April 28, 2020, 8:46pm UTC](https://ask.openrouteservice.org/t/problem-in-the-java-api-matrix-example-on-the-documentation/1632/1 "2020-04-28T20:46:39Z")

</div>

Hello,

I´m trying to run this matrix example provided on the documentation in Java ([here](https://openrouteservice.org/dev/#/api-docs/v2/matrix/%7Bprofile%7D/post)):

```
Client client = ClientBuilder.newClient();
Entity<String> payload = Entity.json({"locations":[[9.70093,48.477473],[9.207916,49.153868],[37.573242,55.801281],[115.663757,38.106467]]});
Response response = client.target("https://api.openrouteservice.org/v2/matrix/driving-car")
  .request()
  .header("Authorization", "api_key")
  .header("Accept", "application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8")
  .header("Content-Type", "application/json; charset=utf-8")
  .post(payload);

System.out.println("status: " + response.getStatus());
System.out.println("headers: " + response.getHeaders());
System.out.println("body:" + response.readEntity(String.class));

```

However **I’m getting an error on this line** :` Entity<String> payload = Entity.json({"locations":[[9.70093,48.477473],[9.207916,49.153868],[37.573242,55.801281],[115.663757,38.106467]]});`

**The error is this one:**  
Multiple markers at this line  
- Syntax error, insert “;” to complete  
LocalVariableDeclarationStatement  
- The method json(T) in the type Entity is not applicable for the  
arguments ()  
- Syntax error on tokens, delete these tokens  
- Syntax error, insert “)” to complete MethodInvocation

Since this is a straight up copy from the documentation and I’m relatively new to this matter, does anyone know how to solve it ?

Thanks

---

<div class="post-metadata">

### Author: ![nils](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/nils/32/6_2.png) [@nils](https://ask.openrouteservice.org/u/nils)
#### Post date: [April 29, 2020, 6:31am UTC](https://ask.openrouteservice.org/t/problem-in-the-java-api-matrix-example-on-the-documentation/1632/2 "2020-04-29T06:31:05Z")

</div>

Please use proper (code) formatting, i.e. 3 backticks, it really hurts my brain to look at it otherwise.

The code on our documentation is auto-generated, we don’t write any of it. Maybe some of the backend folks will point out the mistake and we can override the code piece.

---

<div class="post-metadata">

### Author: ![HendrikLeuschner](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/hendrikleuschner/32/509_2.png) [@HendrikLeuschner](https://ask.openrouteservice.org/u/HendrikLeuschner)
#### Post date: [April 29, 2020, 8:30am UTC](https://ask.openrouteservice.org/t/problem-in-the-java-api-matrix-example-on-the-documentation/1632/3 "2020-04-29T08:30:22Z")

</div>

Hi,

without checking properly, just an idea:  
The example is a `<String>` type Entity. But what is passed is a String followed by an array of floats/doubles. I think you need to either change the type or make the whole statement a String.

---

<div class="post-metadata">

### Author: ![amandus](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/amandus/32/669_2.png) [@amandus](https://ask.openrouteservice.org/u/amandus)
#### Post date: [April 29, 2020, 10:32am UTC](https://ask.openrouteservice.org/t/problem-in-the-java-api-matrix-example-on-the-documentation/1632/4 "2020-04-29T10:32:14Z")

</div>

Hi @Pedro_Pereira,

First of all, please don’t ever expose your _api\_key_ or other people might use it!

I just tested this out shortly and @HendrikLeuschner is right.

You need to pass:

```auto
        Entity<String> payload = Entity.json(
                "{\"locations\":[[9.70093,48.477473],[9.207916,49.153868],[37.573242,55.801281],[115.663757,38.106467]]}"
        );

```

and everything will work without a problem.

Please read [403 Forbidden - Daily quota reached or API key unauthorized](https://ask.openrouteservice.org/t/403-forbidden-daily-quota-reached-or-api-key-unauthorized/495/23)  
for further info on the escape strings.

Best regards

---

<div class="post-metadata">

### Author: ![Pedro\_Pereira](https://ask.openrouteservice.org/user_avatar/ask.openrouteservice.org/pedro_pereira/32/508_2.png) [@Pedro\_Pereira](https://ask.openrouteservice.org/u/Pedro_Pereira)
#### Post date: [April 29, 2020, 11:00am UTC](https://ask.openrouteservice.org/t/problem-in-the-java-api-matrix-example-on-the-documentation/1632/5 "2020-04-29T11:00:14Z")

</div>

Thank you all for your answers. The problem is solved following the solution provided by @amandus .
