Class $Gson$Types


  • public final class $Gson$Types
    extends Object
    Static methods for working with types.
    Author:
    Bob Lee, Jesse Wilson
    • Method Detail

      • newParameterizedTypeWithOwner

        public static ParameterizedType newParameterizedTypeWithOwner​(Type ownerType,
                                                                      Type rawType,
                                                                      Type... typeArguments)
        Returns a new parameterized type, applying typeArguments to rawType and enclosed by ownerType.
        Returns:
        a serializable parameterized type.
      • arrayOf

        public static GenericArrayType arrayOf​(Type componentType)
        Returns an array type whose elements are all instances of componentType.
        Returns:
        a serializable generic array type.
      • subtypeOf

        public static WildcardType subtypeOf​(Type bound)
        Returns a type that represents an unknown type that extends bound. For example, if bound is CharSequence.class, this returns ? extends CharSequence. If bound is Object.class, this returns ?, which is shorthand for ? extends Object.
      • supertypeOf

        public static WildcardType supertypeOf​(Type bound)
        Returns a type that represents an unknown supertype of bound. For example, if bound is String.class, this returns ? super String.
      • canonicalize

        public static Type canonicalize​(Type type)
        Returns a type that is functionally equal but not necessarily equal according to Object.equals(). The returned type is Serializable.
      • getRawType

        public static Class<?> getRawType​(Type type)
      • equals

        public static boolean equals​(Type a,
                                     Type b)
        Returns true if a and b are equal.
      • typeToString

        public static String typeToString​(Type type)
      • getArrayComponentType

        public static Type getArrayComponentType​(Type array)
        Returns the component type of this array type.
        Throws:
        ClassCastException - if this type is not an array.
      • getCollectionElementType

        public static Type getCollectionElementType​(Type context,
                                                    Class<?> contextRawType)
        Returns the element type of this collection type.
        Throws:
        IllegalArgumentException - if this type is not a collection.
      • getMapKeyAndValueTypes

        public static Type[] getMapKeyAndValueTypes​(Type context,
                                                    Class<?> contextRawType)
        Returns a two element array containing this map's key and value types in positions 0 and 1 respectively.
      • resolve

        public static Type resolve​(Type context,
                                   Class<?> contextRawType,
                                   Type toResolve)