Package name.martingeisse.grumpyjson
Class TypeToken<T>
java.lang.Object
name.martingeisse.grumpyjson.TypeToken<T>
- Type Parameters:
T- the type to represent
This class is an easier way to represent a (parameterized) type than
Type. It solves the
following problem: To request deserialization of a type like List<String> from the JSON engine,
that type must be specified. A class object cannot include type arguments, so won't do, and a Type
would work but is cumbersome to get. This class solves the problem like so:
new TypeToken<List<String>>() {}
The type to represent is given as a type argument to this class. It is important to create an anonymous subclass -- hence the curly braces -- because that carries the type information from compile-time to run-time.
This class does not support any other features than getting the Type, such as equals/hashCode or type
analysis.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
TypeToken
protected TypeToken()Constructor
-
-
Method Details
-
getType
Obtains the type represented by this type token.- Returns:
- the type
-