deleted unused visitCollection method in the visitor. All of this functionality has now been replaced with the default CollectionTypeAdapter

This commit is contained in:
Inderjeet Singh 2008-11-14 02:25:41 +00:00
parent bc2c25f235
commit 0b6bbaf5f1
5 changed files with 2 additions and 61 deletions

View File

@ -19,7 +19,6 @@ package com.google.gson;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Collection;
/**
* A visitor that populates fields of an object with data from its equivalent
@ -86,19 +85,6 @@ final class JsonArrayDeserializationVisitor<T> extends JsonDeserializationVisito
}
}
@SuppressWarnings("unchecked")
public void visitCollection(Collection collection, Type collectionType) {
Type childType = TypeUtils.getActualTypeForFirstTypeVariable(collectionType);
for (JsonElement jsonChild : json.getAsJsonArray()) {
if (childType == Object.class) {
throw new JsonParseException(collection +
" must not be a raw collection. Try making it genericized instead.");
}
Object child = visitChild(childType, jsonChild);
collection.add(child);
}
}
@SuppressWarnings("unchecked")
public void visitPrimitiveValue(Object obj) {
target = (T) typeAdapter.adaptType(json.getAsJsonArray().get(0).getAsObject(), componentType);

View File

@ -50,12 +50,6 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
// do nothing
}
public void visitCollection(@SuppressWarnings("unchecked")Collection collection,
Type componentType) {
// should not be called since this case should invoke JsonArrayDeserializationVisitor
throw new IllegalStateException();
}
public void visitArray(Object array, Type componentType) {
// should not be called since this case should invoke JsonArrayDeserializationVisitor
throw new IllegalStateException();

View File

@ -18,7 +18,6 @@ package com.google.gson;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Collection;
/**
* A visitor that populates a primitive value from its JSON representation
@ -48,12 +47,6 @@ final class JsonPrimitiveDeserializationVisitor<T> extends JsonDeserializationVi
// do nothing
}
public void visitCollection(@SuppressWarnings("unchecked")Collection collection,
Type componentType) {
// should not be called since this case should invoke JsonArrayDeserializationVisitor
throw new IllegalStateException();
}
public void visitArray(Object array, Type componentType) {
// should not be called since this case should invoke JsonArrayDeserializationVisitor
throw new IllegalStateException();

View File

@ -66,19 +66,6 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
}
}
@SuppressWarnings("unchecked")
public void visitCollection(Collection collection, Type collectionType) {
assignToRoot(new JsonArray());
for (Object child : collection) {
Type childType = TypeUtils.getActualTypeForFirstTypeVariable(collectionType);
if (childType == Object.class && child != null) {
// Try our luck some other way
childType = child.getClass();
}
addAsArrayElement(childType, child);
}
}
public void visitArrayField(Field f, Type typeOfF, Object obj) {
if (isFieldNull(f, obj)) {
if (serializeNulls) {
@ -187,13 +174,6 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
@SuppressWarnings("unchecked")
public boolean visitUsingCustomHandler(Object obj, Type objType) {
JsonSerializer serializer = serializers.getHandlerFor(objType);
// if (serializer == null) {
// if (obj instanceof Map) {
// serializer = serializers.getHandlerFor(Map.class);
// } else if (obj instanceof Collection) {
// serializer = serializers.getHandlerFor(Collection.class);
// }
// }
if (serializer != null) {
if (obj == null) {
assignToRoot(JsonNull.INSTANCE);

View File

@ -19,7 +19,6 @@ package com.google.gson;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Collection;
/**
* Provides ability to apply a visitor to an object and all of its fields recursively.
@ -40,13 +39,6 @@ final class ObjectNavigator {
*/
void endVisitingObject(Object node);
/**
* This is called to visit the current object if it is an iterable
*
* @param componentType the type of each element of the component
*/
void visitCollection(@SuppressWarnings("unchecked") Collection collection, Type componentType);
/**
* This is called to visit the current object if it is an array
*/
@ -137,12 +129,8 @@ final class ObjectNavigator {
try {
boolean visitedWithCustomHandler = visitor.visitUsingCustomHandler(obj, objType);
if (!visitedWithCustomHandler) {
if (objTypeInfo.isCollectionOrArray()) {
if (objTypeInfo.isArray()) {
visitor.visitArray(obj, objType);
} else { // must be a collection
visitor.visitCollection((Collection<?>) obj, objType);
}
if (objTypeInfo.isArray()) {
visitor.visitArray(obj, objType);
} else if (objTypeInfo.isEnum()) {
visitor.visitEnum(obj, objType);
} else if (objTypeInfo.isPrimitiveOrStringAndNotAnArray()) {