title: gson error: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 166
body: <p>I have following class <code>SolrFBLocationDoc</code>:</p>
  
  <pre><code>public class SolrFBLocationDoc{
  
      @Field
      private String name;
      @Field
      private String id;
      @Field
      private Location location = new Location();
  
      //and some more class members
  }
  </code></pre>
  
  <p>where, <code>Location</code> is a class from restfb: <code>com.restfb.types.Location</code>.</p>
  
  <p>I'm trying to convert a <code>solrDocument</code> to an object of class <code>SolrFBLocationDoc</code> as given below:</p>
  
  <pre><code>SolrFBLocationDoc doc = gson.fromJson(gson.toJson(solrDoc), SolrFBLocationDoc.class);
  </code></pre>
  
  <p>where, <code>solrDoc</code> is:</p>
  
  <pre><code>SolrDocument[{id=106377336067638, location=Location[city=null country=null latitude=null longitude=null state=null street=null zip=null]}]
  </code></pre>
  
  <p>and <code>gson.toJson(solrDoc)</code> returns,</p>
  
  <pre><code>{"id":"106377336067638","location":"Location[city\u003dnull country\u003dnull latitude\u003dnull longitude\u003dnull state\u003dnull street\u003dnull zip\u003dnull]"}
  </code></pre>
  
  <p>But, it's resulting into the error:</p>
  
  <pre><code>com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 166
  </code></pre>
  
  <p>I can see the problem is occuring due to conversion of <code>Location</code> class object to String by <code>gson.toJson(solrDoc)</code>.</p>
  
  <p>Then without using <code>gson.toJson(solrDoc)</code>, how can I convert <code>SolrDocument</code> to <code>SolrFBLocationDoc</code>?</p>
  
  <p>How can I get rid of this problem?</p>