title: Serialize java object with GSON
body: <p>I would like to serialize this object to JSON String</p>
  
  <pre><code>public class Person {
     public String id;
     public String name;
     public Person parent;
  }
  </code></pre>
  
  <p>and obtain a result like this:</p>
  
  <pre><code>{id: 1, name: "Joe", parent: 2}
  </code></pre>
  
  <p>I tried to use</p>
  
  <pre><code>Person p = new Person(1, "Joe", new Person(2, "Mike"));
  Gson gson = new GsonBuilder()
              .registerTypeAdapter(Persona.class, new PersonSerializer()).create();
  String str = gson.toJson(p);
  </code></pre>
  
  <p>but instead of that, I got:</p>
  
  <pre><code>"1"
  </code></pre>
  
  <p>PersonSerializer: </p>
  
  <pre><code>public class PersonSerializer implements JsonSerializer&lt;Person&gt; {
      public JsonElement serialize(Person src, Type typeOfSrc, ...) {
          return new JsonPrimitive(src.id);
      }
  }
  </code></pre>
  
  <p>Please any suggestion is welcome</p>
  
  <p>Thanks,
  Mario</p>