title: GSON - Deserialize primitive array
body: <p>Consider this simple Json:</p>
  
  <pre><code>{
      "test": [
          0,
          3
      ]
  }
  </code></pre>
  
  <p>Now I want to deserialize it in a simple int array so for that I use a custom deserializer:</p>
  
  <pre><code>class ArrayDeserializer implements JsonDeserializer&lt;int[]&gt; {
      @Override
      public int[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
          return context.deserialize(json.getAsJsonObject().getAsJsonArray("test"), int[].class);
      }
  }
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>Gson gson = new GsonBuilder().registerTypeAdapter(int[].class, new ArrayDeserializer()).create();
  int[] arr = gson.fromJson(json, int[].class);
  </code></pre>
  
  <p>which throws:</p>
  
  <pre><code>Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Not a JSON Object: [0,3]
  </code></pre>
  
  <p>However when I do this:</p>
  
  <pre><code>class ArrayDeserializer implements JsonDeserializer&lt;int[]&gt; {
  
      private static final Gson gson = new Gson();
  
      @Override
      public int[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
          return gson.fromJson(json.getAsJsonObject().getAsJsonArray("test"), int[].class);
      }
  }
  </code></pre>
  
  <p>it works and I get the expected output. Why?</p>