title: Mapping specific JSON to Java object
body: <p>I'm trying to map specific JSON to my Java Model class. And am having trouble mapping it to the Java object.</p>
  
  <p>I'm using <em>fasterxml</em> (jackson) to map JSON to my Java Model class below - <strong>CurrencyModel.java</strong>. This JSON have '<strong>[</strong>' at the beginning which it probably means that it is an array. I cannot map it into my class, CurrencyModel.java</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.JsonProperty;
  import lombok.AllArgsConstructor;
  import lombok.Data;
  import lombok.NoArgsConstructor;
  
  import java.util.ArrayList;
  import java.util.List;
  
  class CurrencyModel {
      protected List&lt;Currencies&gt; currencies;
      protected List&lt;CurrenciesRates&gt; currenciesRates;
  
      @Data
      @NoArgsConstructor
      @AllArgsConstructor
      static class Currencies {
          @JsonProperty("table")
          private String table;
  
          @JsonProperty("no")
          private String no;
  
          @JsonProperty("effectiveDate")
          private String effectiveDate;
  
          @JsonProperty("rates")
          private ArrayList&lt;CurrencyRatesModel&gt; rates;
      }
  
      @Data
      @NoArgsConstructor
      @AllArgsConstructor
      static class CurrenciesRates {
          @JsonProperty("currency")
          private String currency;
  
          @JsonProperty("code")
          private String code;
  
          @JsonProperty("mid")
          private String mid;
      }
  }
  </code></pre>
  
  <p>And having JSON below in String variable </p>
  
  <pre><code>[
    {
      "table": "A",
      "no": "064/A/NBP/2013",
      "effectiveDate": "2013-04-02",
      "rates": [
        {
          "currency": "bat (Tajlandia)",
          "code": "THB",
          "mid": 0.1108
        },
        {
          "currency": "dolar amerykański",
          "code": "USD",
          "mid": 3.2552
        },
        {
          "currency": "dolar australijski",
          "code": "AUD",
          "mid": 3.4048
        }
      ]
    }
  ]
  </code></pre>
  
  <p>I'm trying to run this code using:</p>
  
  <pre><code>ObjectMapper objectMapper = new ObjectMapper();
  final String output = "[{\"table\": \"A\", \"no\": \"064/A/NBP/2013\",\"effectiveDate\": \"2013-04-02\",\"rates\": [{\"currency\": \"bat (Tajlandia)\",\"code\": \"THB\",\"mid\": 0.1108},{\"currency\": \"dolar amerykański\",\"code\": \"USD\",\"mid\": 3.2552},{\"currency\": \"dolar australijski\",\"code\": \"AUD\",\"mid\": 3.4048}]}]";
  List&lt;CurrencyModel&gt; currencyModelList = Arrays.asList(objectMapper.readValue(output, CurrencyModel.class));
  objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
  System.out.println(currencyModelList.toArray());
  </code></pre>
  
  <p>which results in error:</p>
  
  <pre><code>com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `` out of START_ARRAY token
  </code></pre>