java.lang.Object
com.github.natche.gravatarjavaclient.profile.gson.Types

public final class Types extends Object
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 Details

    • collectionOf

      public static <E> com.google.common.reflect.TypeToken<Collection<E>> collectionOf(Type type)
      Creates a TypeToken representing a Collection of 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