title: Why does Gson fromJson throw a JsonSyntaxException: Expected BEGIN_OBJECT but was BEGIN_ARRAY?
body: <p>(This post is meant to be a <a href="https://meta.stackoverflow.com/questions/291992/what-is-a-canonical-question-answer-and-what-is-their-purpose">canonical question</a> with a sample answer provided below.)</p>
  
  <hr>
  
  <p>I'm trying to deserialize some JSON content into a custom POJO type with <a href="https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html#fromJson%28java.lang.String,%20java.lang.Class%29" rel="noreferrer"><code>Gson#fromJson(String, Class)</code></a>.</p>
  
  <p>This piece of code</p>
  
  <pre><code>import com.google.gson.Gson;
  
  public class Sample {
      public static void main(String[] args) {
          String json = "{\"nestedPojo\":[{\"name\":null, \"value\":42}]}";
          Gson gson = new Gson();
          gson.fromJson(json, Pojo.class);
      }
  }
  
  class Pojo {
      NestedPojo nestedPojo;
  }
  
  class NestedPojo {
      String name;
      int value;
  }
  </code></pre>
  
  <p>throws the follow exception</p>
  
  <pre><code>Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 16 path $.nestedPojo
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200)
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
      at com.google.gson.Gson.fromJson(Gson.java:810)
      at com.google.gson.Gson.fromJson(Gson.java:775)
      at com.google.gson.Gson.fromJson(Gson.java:724)
      at com.google.gson.Gson.fromJson(Gson.java:696)
      at com.example.Sample.main(Sample.java:23)
  Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 16 path $.nestedPojo
      at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:387)
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:189)
      ... 7 more
  </code></pre>
  
  <p>Why can't Gson properly convert my JSON text to my POJO type?</p>