deleted unused visitCollection method in the visitor. All of this functionality has now been replaced with the default CollectionTypeAdapter
This commit is contained in:
parent
bc2c25f235
commit
0b6bbaf5f1
|
@ -19,7 +19,6 @@ package com.google.gson;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A visitor that populates fields of an object with data from its equivalent
|
* 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")
|
@SuppressWarnings("unchecked")
|
||||||
public void visitPrimitiveValue(Object obj) {
|
public void visitPrimitiveValue(Object obj) {
|
||||||
target = (T) typeAdapter.adaptType(json.getAsJsonArray().get(0).getAsObject(), componentType);
|
target = (T) typeAdapter.adaptType(json.getAsJsonArray().get(0).getAsObject(), componentType);
|
||||||
|
|
|
@ -50,12 +50,6 @@ final class JsonObjectDeserializationVisitor<T> extends JsonDeserializationVisit
|
||||||
// do nothing
|
// 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) {
|
public void visitArray(Object array, Type componentType) {
|
||||||
// should not be called since this case should invoke JsonArrayDeserializationVisitor
|
// should not be called since this case should invoke JsonArrayDeserializationVisitor
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
|
|
@ -18,7 +18,6 @@ package com.google.gson;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A visitor that populates a primitive value from its JSON representation
|
* A visitor that populates a primitive value from its JSON representation
|
||||||
|
@ -48,12 +47,6 @@ final class JsonPrimitiveDeserializationVisitor<T> extends JsonDeserializationVi
|
||||||
// do nothing
|
// 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) {
|
public void visitArray(Object array, Type componentType) {
|
||||||
// should not be called since this case should invoke JsonArrayDeserializationVisitor
|
// should not be called since this case should invoke JsonArrayDeserializationVisitor
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
|
|
@ -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) {
|
public void visitArrayField(Field f, Type typeOfF, Object obj) {
|
||||||
if (isFieldNull(f, obj)) {
|
if (isFieldNull(f, obj)) {
|
||||||
if (serializeNulls) {
|
if (serializeNulls) {
|
||||||
|
@ -187,13 +174,6 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public boolean visitUsingCustomHandler(Object obj, Type objType) {
|
public boolean visitUsingCustomHandler(Object obj, Type objType) {
|
||||||
JsonSerializer serializer = serializers.getHandlerFor(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 (serializer != null) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
assignToRoot(JsonNull.INSTANCE);
|
assignToRoot(JsonNull.INSTANCE);
|
||||||
|
|
|
@ -19,7 +19,6 @@ package com.google.gson;
|
||||||
import java.lang.reflect.AccessibleObject;
|
import java.lang.reflect.AccessibleObject;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides ability to apply a visitor to an object and all of its fields recursively.
|
* 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);
|
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
|
* This is called to visit the current object if it is an array
|
||||||
*/
|
*/
|
||||||
|
@ -137,12 +129,8 @@ final class ObjectNavigator {
|
||||||
try {
|
try {
|
||||||
boolean visitedWithCustomHandler = visitor.visitUsingCustomHandler(obj, objType);
|
boolean visitedWithCustomHandler = visitor.visitUsingCustomHandler(obj, objType);
|
||||||
if (!visitedWithCustomHandler) {
|
if (!visitedWithCustomHandler) {
|
||||||
if (objTypeInfo.isCollectionOrArray()) {
|
if (objTypeInfo.isArray()) {
|
||||||
if (objTypeInfo.isArray()) {
|
visitor.visitArray(obj, objType);
|
||||||
visitor.visitArray(obj, objType);
|
|
||||||
} else { // must be a collection
|
|
||||||
visitor.visitCollection((Collection<?>) obj, objType);
|
|
||||||
}
|
|
||||||
} else if (objTypeInfo.isEnum()) {
|
} else if (objTypeInfo.isEnum()) {
|
||||||
visitor.visitEnum(obj, objType);
|
visitor.visitEnum(obj, objType);
|
||||||
} else if (objTypeInfo.isPrimitiveOrStringAndNotAnArray()) {
|
} else if (objTypeInfo.isPrimitiveOrStringAndNotAnArray()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user