Closed GoogleCodeExporter closed 9 years ago
You need to use the two-arg form of Gson.toJson():
new Gson().toJson(o, new TypeToken<<MyObject<String>>() {});
Otherwise GSON doesn't have the type information that it needs to do a good job.
Original comment by limpbizkit
on 29 Jul 2011 at 4:23
Ok I just learnt I was confused between compile time and runtime valorization
of parameteried types (if we use List<String> as an attribute in a class it
will work well).
However, wouldn't be worth to throw an exception instead of serializing an
empty object when we are in such a case where no TypeToken is given on a
generic type ?
Original comment by fcamb...@gmail.com
on 29 Jul 2011 at 7:10
@fcamblor yeah, I agree that our behavior is confusing. Often the current
behavior is useful when you're serializing a giant graph of things and you
don't necessarily care about everything.
Original comment by limpbizkit
on 29 Jul 2011 at 1:25
Issue 351 has been merged into this issue.
Original comment by limpbizkit
on 2 Aug 2011 at 6:22
Original issue reported on code.google.com by
fcamb...@gmail.com
on 28 Jul 2011 at 3:15Attachments: