title: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY
body: <p>I am trying to parse the incoming Json (given below) to Java object using Gson. The Json request seems to be a valid one, but I am getting the following exception while parsing it.</p>
  
  <pre><code>com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 5 column 19 path $.metadata.
          at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226) ~[gson-2.8.5.jar:?]
          at com.google.gson.Gson.fromJson(Gson.java:927) ~[gson-2.8.5.jar:?]
  </code></pre>
  
  <p>Incoming Json request :</p>
  
  <pre><code>{
      "metadata": {
          "salesId": "123",
          "promoCode": "2010",
          "items": [
              {
                  "0": {
                      "productCode": "1234",
                      "total": 169900
                  },
                  "1": {
                      "productCode": "4567",
                      "total": 19900
                  }
              }
          ]
      }
  }
  </code></pre>
  
  <p>Parsing logic : </p>
  
  <pre><code>protected &lt;T extends GenericModel&gt; Optional&lt;T&gt; convertFromJson(final String json, final Class&lt;T&gt; clazz) {
          if (StringUtils.isEmpty(json)) {
              return Optional.empty();
          }
          return Optional.of(new Gson().fromJson(json, clazz));
      }
  </code></pre>
  
  <p>Java class :</p>
  
  <pre><code>public class Metadata {
      private String salesId;
      private String promoCode;
      private ArrayList&lt;Object&gt; items = new ArrayList&lt;Object&gt;();
  
      public String getSalesId() {
          return salesId;
      }
  
      public void setSalesId(String salesId) {
          this.salesId = salesId;
      }
  
      public String getPromoCode() {
          return promoCode;
      }
  
      public void setPromoCode(String promoCode) {
          this.promoCode = promoCode;
      }
  
      public ArrayList&lt;Object&gt; getItems() {
          return items;
      }
  
      public void setItems(ArrayList&lt;Object&gt; items) {
          this.items = items;
      }
  
      @Override
      public String toString() {
          return "Metadata{" +
                  "salesId=" + getSalesId() +
                  "promoCode=" + getPromoCode() +
                  "items=" + getItems() +
                  '}';
      }
  }
  </code></pre>
  
  <p>Please note that Metadata.java is an inner class.</p>
  
  <p>Have been trying to resolve the issue, but no luck. Could anyone let me know how to solve it? TIA.</p>