title: Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2
body: <p>I am using Gson API 2.4.2 for parsing json data.Please find below my json data</p>
  
  <pre><code>var data = {
              "timezoneId" : timezoneId,
              "companyId" : companyId,
              "testId" : testId,
              "graphType" : graphType,
              "locationId":locationId
             };
  </code></pre>
  
  <p>here values of timezoneId,companyId etc are dynamically generated from java script file thats why they are not hardcoded and i have inspect from my browser that values are comming properly.Now,In backed I have a JSF bean class as follows:</p>
  
  <pre><code>    package com.edfx.warm.bean;
      import java.io.Serializable;
  
      public class ResponseInfoForJSON implements Serializable {
  
        private static final long serialVersionUID = -40538895168761693L;
        private String timezoneId;
        private String companyId;
        private String testId;
        private String graphType;
        private String locationId;
  
        public String getTimezoneId() {
          return timezoneId;
        }
  
        public void setTimezoneId(String timezoneId) {
          this.timezoneId = timezoneId;
        }
  
        public String getCompanyId() {
          return companyId;
        }
  
        public void setCompanyId(String companyId) {
          this.companyId = companyId;
        }
  
        public String getTestId() {
          return testId;
        }
  
        public void setTestId(String testId) {
          this.testId = testId;
        }
  
        public String getGraphType() {
          return graphType;
        }
  
        public void setGraphType(String graphType) {
          this.graphType = graphType;
        }
  
        public String getLocationId() {
          return locationId;
        }
  
        public void setLocationId(String locationId) {
          this.locationId = locationId;
        }
  
        public static long getSerialversionuid() {
          return serialVersionUID;
        }
        }
  </code></pre>
  
  <p>here is my code for converting json to java object</p>
  
  <pre><code>       public void deserializeObjectCollection(String jsonData){
              ResponseInfoForJSON[] responseInfoForJSON=new Gson().fromJson(jsonData, ResponseInfoForJSON[].class);
         }
  </code></pre>
  
  <p>during conversion I am getting the following error</p>
  
  <pre><code>        Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2
          at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveType AdapterFactory.java:176) [gson-2.2.4.jar:]
          at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) [gson-2.2.4.jar:]
          at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72) [gson-2.2.4.jar:]
          at com.google.gson.Gson.fromJson(Gson.java:803) [gson-2.2.4.jar:]
          at com.google.gson.Gson.fromJson(Gson.java:768) [gson-2.2.4.jar:]
          at com.google.gson.Gson.fromJson(Gson.java:717) [gson-2.2.4.jar:]
          at com.google.gson.Gson.fromJson(Gson.java:689) [gson-2.2.4.jar:]
          at com.edfx.warm.bean.ChartBean.deserializeObjectCollection(ChartBean.java:83) [classes:]
  </code></pre>
  
  <p>I have gone through the other post on this topic in stackoverflow but unable to figure out my problem.If I change my deserialization code to following:</p>
  
  <pre><code>        ResponseInfoForJSON responseInfoForJSON=new Gson().fromJson(jsonData, ResponseInfoForJSON.class);
  </code></pre>
  
  <p>Then I got the following error:</p>
  
  <pre><code>        java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
          at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:374) [gson-2.2.4.jar:]
          at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:165) [gson-2.2.4.jar:]
  </code></pre>
  
  <p>Can anyone provide any solution to this???
    Thanks in advance.</p>