Added support for constructing Queues and SortedSet while handling collections.

This commit is contained in:
Inderjeet Singh 2011-09-09 05:49:30 +00:00
parent f3c0a96f44
commit 6f6d3b221e
2 changed files with 10 additions and 3 deletions

View File

@ -22,8 +22,12 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import com.google.gson.internal.$Gson$Types;
import com.google.gson.reflect.TypeToken;
@ -53,10 +57,13 @@ public final class CollectionTypeAdapter<E> extends TypeAdapter<Collection<E>> {
constructorType = ArrayList.class;
} else if (rawType == Set.class) {
constructorType = LinkedHashSet.class;
} else if (rawType == Queue.class) {
constructorType = LinkedList.class;
} else if (rawType == SortedSet.class) {
constructorType = TreeSet.class;
} else {
constructorType = rawType;
}
// TODO: Queue=LinkedList, SortedSet=TreeSet
Constructor<?> constructor = null;
try {

View File

@ -166,8 +166,8 @@ public final class MiniGson {
return this;
}
public <T> Builder typeHierarchyAdapter(Class<T> clazz, TypeAdapter<T> typeAdapter) {
factories.add(TypeAdapters.newTypeHierarchyFactory(clazz, typeAdapter));
public <T> Builder typeHierarchyAdapter(Class<T> type, TypeAdapter<T> typeAdapter) {
factories.add(TypeAdapters.newTypeHierarchyFactory(type, typeAdapter));
return this;
}