Added support for constructing Queues and SortedSet while handling collections.
This commit is contained in:
parent
f3c0a96f44
commit
6f6d3b221e
|
@ -22,8 +22,12 @@ import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import com.google.gson.internal.$Gson$Types;
|
import com.google.gson.internal.$Gson$Types;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
@ -53,10 +57,13 @@ public final class CollectionTypeAdapter<E> extends TypeAdapter<Collection<E>> {
|
||||||
constructorType = ArrayList.class;
|
constructorType = ArrayList.class;
|
||||||
} else if (rawType == Set.class) {
|
} else if (rawType == Set.class) {
|
||||||
constructorType = LinkedHashSet.class;
|
constructorType = LinkedHashSet.class;
|
||||||
|
} else if (rawType == Queue.class) {
|
||||||
|
constructorType = LinkedList.class;
|
||||||
|
} else if (rawType == SortedSet.class) {
|
||||||
|
constructorType = TreeSet.class;
|
||||||
} else {
|
} else {
|
||||||
constructorType = rawType;
|
constructorType = rawType;
|
||||||
}
|
}
|
||||||
// TODO: Queue=LinkedList, SortedSet=TreeSet
|
|
||||||
|
|
||||||
Constructor<?> constructor = null;
|
Constructor<?> constructor = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -166,8 +166,8 @@ public final class MiniGson {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> Builder typeHierarchyAdapter(Class<T> clazz, TypeAdapter<T> typeAdapter) {
|
public <T> Builder typeHierarchyAdapter(Class<T> type, TypeAdapter<T> typeAdapter) {
|
||||||
factories.add(TypeAdapters.newTypeHierarchyFactory(clazz, typeAdapter));
|
factories.add(TypeAdapters.newTypeHierarchyFactory(type, typeAdapter));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user