title: Deserialize a json array to objects using Jackson and WebClient
body: <p>I have a problem during the deserialization of a json array using Spring.
  I have this json response from a service:</p>
  
  <pre><code>[
      {
          "symbol": "XRPETH",
          "orderId": 12122,
          "clientOrderId": "xxx",
          "price": "0.00000000",
          "origQty": "25.00000000",
          "executedQty": "25.00000000",
          "status": "FILLED",
          "timeInForce": "GTC",
          "type": "MARKET",
          "side": "BUY",
          "stopPrice": "0.00000000",
          "icebergQty": "0.00000000",
          "time": 1514558190255,
          "isWorking": true
      },
      {
          "symbol": "XRPETH",
          "orderId": 1212,
          "clientOrderId": "xxx",
          "price": "0.00280000",
          "origQty": "24.00000000",
          "executedQty": "24.00000000",
          "status": "FILLED",
          "timeInForce": "GTC",
          "type": "LIMIT",
          "side": "SELL",
          "stopPrice": "0.00000000",
          "icebergQty": "0.00000000",
          "time": 1514640491287,
          "isWorking": true
      },
      ....
  ]
  </code></pre>
  
  <p>I get this json using the new WebClient from Spring WebFlux, here the code:</p>
  
  <pre><code>@Override
      public Mono&lt;AccountOrderList&gt; getAccountOrders(String symbol) {
          return binanceServerTimeApi.getServerTime().flatMap(serverTime -&gt; {
              String apiEndpoint = "/api/v3/allOrders?";
              String queryParams = "symbol=" +symbol.toUpperCase() + "&amp;timestamp=" + serverTime.getServerTime();
              String signature = HmacSHA256Signer.sign(queryParams, secret);
              String payload = apiEndpoint + queryParams + "&amp;signature="+signature;
              log.info("final endpoint:"+ payload);
              return this.webClient
                      .get()
                      .uri(payload)
                      .accept(MediaType.APPLICATION_JSON)
                      .retrieve()
                      .bodyToMono(AccountOrderList.class)
                      .log();
          });
      }
  </code></pre>
  
  <p>AccountOrderList</p>
  
  <pre><code>public class AccountOrderList {
  
      private List&lt;AccountOrder&gt; accountOrders;
  
      public AccountOrderList() {
      }
  
      public AccountOrderList(List&lt;AccountOrder&gt; accountOrders) {
          this.accountOrders = accountOrders;
      }
  
      public List&lt;AccountOrder&gt; getAccountOrders() {
          return accountOrders;
      }
  
      public void setAccountOrders(List&lt;AccountOrder&gt; accountOrders) {
          this.accountOrders = accountOrders;
      }
  }
  </code></pre>
  
  <p>AccountOrder is a simple pojo that maps the fields.</p>
  
  <p>Actually, when I hit a get it says:</p>
  
  <pre><code>org.springframework.core.codec.DecodingException: JSON decoding error: Cannot deserialize instance of `io.justin.demoreactive.domain.AccountOrder` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `io.justin.demoreactive.domain.AccountOrder` out of START_ARRAY token
   at [Source: UNKNOWN; line: -1, column: -1]
  </code></pre>
  
  <p>How can I deserialize the json properly using the new webflux module? What am I doing wrong? </p>
  
  <p><strong>UPDATE 05/02/2018</strong></p>
  
  <p>Both answers are correct. They addressed perfectly my question but at the end I decided to use a slightly different approach:</p>
  
  <pre><code>@Override
      public Mono&lt;List&lt;AccountOrder&gt;&gt; getAccountOrders(String symbol) {
          return binanceServerTimeApi.getServerTime().flatMap(serverTime -&gt; {
              String apiEndpoint = "/api/v3/allOrders?";
              String queryParams = "symbol=" +symbol.toUpperCase() + "&amp;timestamp=" + serverTime.getServerTime();
              String signature = HmacSHA256Signer.sign(queryParams, secret);
              String payload = apiEndpoint + queryParams + "&amp;signature="+signature;
              log.info("final endpoint:"+ payload);
              return this.webClient
                      .get()
                      .uri(payload)
                      .accept(MediaType.APPLICATION_JSON)
                      .retrieve()
                      .bodyToFlux(AccountOrder.class)
                      .collectList()
                      .log();
          });
      }
  </code></pre>
  
  <p>An alternative to this could be to return directly A Flux so you don't have to convert it to a list. (that's what flux are: a collection of n elements). </p>