From a8133efeb812badc14f00c1e641ee9891bc803b8 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Fri, 9 Sep 2011 04:22:57 +0000 Subject: [PATCH] removed old-style Collections type adapter since the new one covers all cases. --- .../com/google/gson/DefaultTypeAdapters.java | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java index 1c184461..03ae677b 100644 --- a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java +++ b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java @@ -65,7 +65,6 @@ final class DefaultTypeAdapters { @SuppressWarnings("unchecked") private static final EnumTypeAdapter ENUM_TYPE_ADAPTER = new EnumTypeAdapter(); private static final BitSetTypeAdapter BIT_SET_ADAPTER = new BitSetTypeAdapter(); - private static final CollectionTypeAdapter COLLECTION_TYPE_ADAPTER = new CollectionTypeAdapter(); private static final MapTypeAdapter MAP_TYPE_ADAPTER = new MapTypeAdapter(); private static final ByteTypeAdapter BYTE_TYPE_ADAPTER = new ByteTypeAdapter(); @@ -116,7 +115,6 @@ final class DefaultTypeAdapters { ParameterizedTypeHandlerMap> map = new ParameterizedTypeHandlerMap>(); map.registerForTypeHierarchy(Enum.class, ENUM_TYPE_ADAPTER, true); - map.registerForTypeHierarchy(Collection.class, COLLECTION_TYPE_ADAPTER, true); map.registerForTypeHierarchy(Map.class, MAP_TYPE_ADAPTER, true); map.makeUnmodifiable(); return map; @@ -149,7 +147,6 @@ final class DefaultTypeAdapters { ParameterizedTypeHandlerMap> map = new ParameterizedTypeHandlerMap>(); map.registerForTypeHierarchy(Enum.class, wrapDeserializer(ENUM_TYPE_ADAPTER), true); - map.registerForTypeHierarchy(Collection.class, wrapDeserializer(COLLECTION_TYPE_ADAPTER), true); map.registerForTypeHierarchy(Map.class, wrapDeserializer(MAP_TYPE_ADAPTER), true); map.makeUnmodifiable(); return map; @@ -485,58 +482,6 @@ final class DefaultTypeAdapters { } } - @SuppressWarnings("unchecked") - private static final class CollectionTypeAdapter implements JsonSerializer, - JsonDeserializer { - public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) { - if (src == null) { - return JsonNull.INSTANCE; - } - JsonArray array = new JsonArray(); - Type childGenericType = null; - if (typeOfSrc instanceof ParameterizedType) { - Class rawTypeOfSrc = $Gson$Types.getRawType(typeOfSrc); - childGenericType = $Gson$Types.getCollectionElementType(typeOfSrc, rawTypeOfSrc); - } - for (Object child : src) { - if (child == null) { - array.add(JsonNull.INSTANCE); - } else { - Type childType = (childGenericType == null || childGenericType == Object.class) - ? child.getClass() : childGenericType; - JsonElement element = context.serialize(child, childType, false, false); - array.add(element); - } - } - return array; - } - - public Collection deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - if (json.isJsonNull()) { - return null; - } - // Use ObjectConstructor to create instance instead of hard-coding a specific type. - // This handles cases where users are using their own subclass of Collection. - Collection collection = constructCollectionType(typeOfT, context); - Type childType = $Gson$Types.getCollectionElementType(typeOfT, $Gson$Types.getRawType(typeOfT)); - for (JsonElement childElement : json.getAsJsonArray()) { - if (childElement == null || childElement.isJsonNull()) { - collection.add(null); - } else { - Object value = context.deserialize(childElement, childType); - collection.add(value); - } - } - return collection; - } - - private Collection constructCollectionType(Type collectionType, - JsonDeserializationContext context) { - return context.construct(collectionType); - } - } - private static final class NumberTypeAdapter implements JsonSerializer, JsonDeserializer { public JsonElement serialize(Number src, Type typeOfSrc, JsonSerializationContext context) {