/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType)collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); // TODO: strip wildcards? if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
public static Type getYourCollectionElementType(Type context, Class<?> contextRawType, Class<?> yourCollectionType) { Type collectionType = $Gson$Types.getSupertype(context, contextRawType, yourCollectionType); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType) collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; } }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); // TODO: strip wildcards? if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); // TODO: strip wildcards? if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); // TODO: strip wildcards? if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); // TODO: strip wildcards? if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); // TODO: strip wildcards? if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); // TODO: strip wildcards? if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns a two element array containing this map's key and value types in * positions 0 and 1 respectively. */ public static Type[] getMapKeyAndValueTypes(Type context, Class<?> contextRawType) { /* * Work around a problem with the declaration of java.util.Properties. That * class should extend Hashtable<String, String>, but it's declared to * extend Hashtable<Object, Object>. */ if (context == Properties.class) { return new Type[] { String.class, String.class }; // TODO: test subclasses of Properties! } Type mapType = getSupertype(context, contextRawType, Map.class); ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType)collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType)collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType)collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType)collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType)collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType)collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
public static Type getYourCollectionElementType(Type context, Class<?> contextRawType, Class<?> yourCollectionType) { Type collectionType = $Gson$Types.getSupertype(context, contextRawType, yourCollectionType); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType) collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; } }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type getCollectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; }