public JsonElement toJsonTree(Object src, Type typeOfSrc) {
    JsonTreeWriter writer = new JsonTreeWriter();
    toJson(src, typeOfSrc, writer);
    return writer.get();
  }
public JsonElement toJsonTree ( Object src , Type typeOfSrc ) { JsonTreeWriter writer = new JsonTreeWriter ( ) ; toJson ( src , typeOfSrc , writer ) ; return writer . get ( ) ; }
This method serializes the specified object, including those of generic types, into its
equivalent representation as a tree of {@link JsonElement}s. This method must be used if the
specified object is a generic type. For non-generic objects, use {@link #toJsonTree(Object)}
instead.

@param src the object for which JSON representation is to be created
@param typeOfSrc The specific genericized type of src. You can obtain
this type by using the {@link com.google.gson.reflect.TypeToken} class. For example,
to get the type for {@code Collection<Foo>}, you should use:
<pre>
Type typeOfSrc = new TypeToken&lt;Collection&lt;Foo&gt;&gt;(){}.getType();
</pre>
@return Json representation of {@code src}
@since 1.4