Class Types
java.lang.Object
com.github.natche.gravatarjavaclient.profile.gson.Types
Utility class for constructing parameterized type tokens used in Gson deserialization.
This class provides helper methods for creating TypeToken instances that represent
generic collection types, which are necessary for Gson to properly deserialize generic collections.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> com.google.common.reflect.TypeToken<Collection<E>> collectionOf(Type type) Creates aTypeTokenrepresenting aCollectionof the specified element type.
-
Method Details
-
collectionOf
Creates aTypeTokenrepresenting aCollectionof the specified element type.This method is useful for deserializing JSON arrays into strongly-typed collections when using Gson. For example, to deserialize a JSON array into a
Collection<String>:Type collectionType = Types.collectionOf(String.class).getType(); Collection<String> result = gson.fromJson(json, collectionType);- Type Parameters:
E- the element type parameter- Parameters:
type- the element type of the collection- Returns:
- a TypeToken representing
Collection<E> - Throws:
NullPointerException- if type is null
-