title: GSON identifying JSON Object as Primitive
body: <p>I am writing a relatively simple messaging app that saves its logs in the JSON format, and I am using the GSON library to parse these. I load a JSON file from a server, and put it trough <code>Gson.toJsonTree()</code> function. I'm not sure this is expected, but when I test the result from the previous function with the <code>isJsonSomething()</code> functions (<code>isJsonObject</code>,<code>isJsonAray</code>,<code>isJsonNull</code>,<code>isJsonPrimitive</code>), <code>isJsonPrimitive</code> returns true, and I can't parse it into a object. This is my JSON file's contents:</p>
  
  <pre><code>{
      "users": [
          {
              "picture": "", 
              "type": "user", 
              "name": "kroltan"
          }
      ], 
      "description": "No description", 
      "messages": [
  
          {
              "content": "something", 
              "time": "2013-08-30 00:38:17.212000", 
              "type": "message", 
              "author": "someone"
          }
      ], 
      "type": "channel", 
      "name": "default"
  }
  </code></pre>
  
  <p>And here is the class used to parse it into POJOs: (CLEANUP comments is where I've removed irrelevant code from the post)</p>
  
  <pre><code>package com.example.testapp;
  
  //CLEANUP: All needed imports
  
  import com.example.testapp.data.*;
  import com.google.gson.*;
  
  public class JSONConverter {
      public interface JsonTypeLoadedListener {
          public void onSucess(JSONType jsonType);
          public void onFailure(Exception e);
      }
      public static final String DATE_FORMAT = "dd-MM-yyyy HH:mm:ss.SSS";
      public static final HashMap&lt;String, Class&lt;?&gt;&gt; JSON_TYPES = new HashMap&lt;String, Class&lt;?&gt;&gt;();
      public JSONConverter() {
          JSON_TYPES.clear();
          JSON_TYPES.put("channel", Channel.class);
          JSON_TYPES.put("user", User.class);
          JSON_TYPES.put("message", Message.class);
      }
      public void loadFromURL(final URL url, final JsonTypeLoadedListener listener) {
          new Thread(new Runnable() {
  
              @Override
              public void run() {
                  JsonObject result = null;
                  Gson gson = new GsonBuilder().setDateFormat(DATE_FORMAT).create();
                  if (url.getProtocol().equals("http")) {
                      try {
                          String content = //Loads from a server, omitted for clarity
                          result = gson.toJsonTree(content).getAsJsonObject();
                          conn.disconnect();
                      } catch (Exception e) {
                          e.printStackTrace();
                          listener.onFailure(e);
                          return;
                      }
                  } else if (url.getProtocol().equals("file")) {
                      try {
                          String content = //Loads from a file, omitted for clarity
                          result = gson.toJsonTree(content).getAsJsonObject();
                          br.close();
                      } catch (Exception e) {
                          e.printStackTrace();
                          listener.onFailure(e);
                          return;
                      }
                  }
                  listener.onSucess((JSONType) gson.fromJson(result, JSON_TYPES.get(result.get("type").getAsString())));
              }
  
          }, "URLLoader").start();
      }
      public JSONType loadFromString(String s) {
          Gson gson = new Gson();
          JsonObject result = gson.toJsonTree(s).getAsJsonObject();
          return (JSONType) gson.fromJson(result, JSON_TYPES.get(result.get("type").getAsString()));
      }
  }
  </code></pre>
  
  <p>The classes <code>Message</code>, <code>User</code> and <code>Channel</code> all inherit from JSONType (a custom class with a field called type and some utility methods) and contain all values present in the above mentioned JSON file.</p>
  
  <p>When it reaches <code>gson.toJsonTree(content).getAsJsonObject()</code>, I get this error in Logcat (string omitted for clarity, it's just the full file):</p>
  
  <pre><code>java.lang.IllegalStateException: Not a JSON Object: "String containing all the file with tabs represented as \t"
  </code></pre>