From ad921a0ee85303f639e5ce27e9a255125351d031 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Thu, 24 Mar 2011 22:37:03 +0000 Subject: [PATCH] removed unused variable. eliminated unnecessary ObjTypePair creation. --- gson/src/main/java/com/google/gson/ObjectTypePair.java | 7 +++++++ .../java/com/google/gson/ReflectingFieldNavigator.java | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gson/src/main/java/com/google/gson/ObjectTypePair.java b/gson/src/main/java/com/google/gson/ObjectTypePair.java index 6dddd409..afc60060 100644 --- a/gson/src/main/java/com/google/gson/ObjectTypePair.java +++ b/gson/src/main/java/com/google/gson/ObjectTypePair.java @@ -79,6 +79,13 @@ final class ObjectTypePair { return new ObjectTypePair(obj, actualType, preserveType); } + Type getMoreSpecificType() { + if (preserveType || obj == null) { + return type; + } + return getActualTypeIfMoreSpecific(type, obj.getClass()); + } + // This takes care of situations where the field was declared as an Object, but the // actual value contains something more specific. See Issue 54. // TODO (inder): This solution will not work if the field is of a generic type, but diff --git a/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java b/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java index 20424052..bf4f79e6 100644 --- a/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java +++ b/gson/src/main/java/com/google/gson/ReflectingFieldNavigator.java @@ -54,9 +54,7 @@ final class ReflectingFieldNavigator { * @param visitor the visitor to visit each field with */ void visitFieldsReflectively(ObjectTypePair objTypePair, Visitor visitor) { - ObjectTypePair currObjTypePair = objTypePair.toMoreSpecificType(); - Class topLevelClass = Types.getRawType(currObjTypePair.type); - for (Class curr : getInheritanceHierarchy(currObjTypePair.type)) { + for (Class curr : getInheritanceHierarchy(objTypePair.getMoreSpecificType())) { navigateClassFields(objTypePair.getObject(), objTypePair.type, curr, visitor); } }