Q:

How to serialize JSON with Object containing both primitives and List<> types?

So I have a class that I was planning on using for simple JSON serialization.
public class Thing {

  private int field1;
  private String some_other_field;
  private List<SubType> subs;
  private list<AnotherType> another;

  public String toJson() {
    Gson g = new Gson();
    g.toJson(this);
  }
}

So the documentation shows that if you want to serialize generic types, you need to specify a TypeToken:
Type listtype = new TypeToken<List<SubType>>() {}.getType();
gson.toJson(subs, listtype);

But then, how does this work if I have a whole class I want to serialize for?  Where do I get to specify the serialization type for those two List<> types so that I can just pass the whole object in and get a serialized output?  Is that even possible?

A:

From the doc it seems that if you serialize a complete object with toJson(...), it deals with the generics attributes properly.
toJson(Object)
"Note that this method works fine if the any of the object fields are of generic type, just the object itself should not be of a generic type"
What output did you get with your object ?

