Closed GoogleCodeExporter closed 9 years ago
Thanks for sharing your thoughts. It is an interesting approach, and works well
for your List<String> example. On the other hand, it is not descriptive enough
for your Map example. What if it was a Map<K1<K2<K3<K4>>>, V1<V2>>? How would
you know where the key description ends and the value description starts?
Gson API is better off leaving the type construction out of its scope.
In Gson 1.7, we are borrowing Types class from Guice that lets you create
arbitrarily complex parameterized types on the fly. Checkout the latest code or
stay tuned for our public 1.7 release.
Original comment by inder123
on 31 Jan 2011 at 11:31
Your Map example would work equally well. The function #getType() is recursive:
it checks how many generic types a class expects and then walks this tree depth
first.
You would simply specify it in the same order like you define it: (Map, K1, K2,
K3, K4, V1, V2). Where the key description ends is obtained from the actual
class files (class.getTypeParameters().length). As long as nobody invents
variable generics your safe :)
Original comment by goo...@boast.nl
on 1 Feb 2011 at 10:56
Original issue reported on code.google.com by
goo...@boast.nl
on 19 Nov 2010 at 10:16