diff --git a/gson/src/main/java/com/google/gson/Cache.java b/gson/src/main/java/com/google/gson/Cache.java index ed56cd3c..57d710fb 100644 --- a/gson/src/main/java/com/google/gson/Cache.java +++ b/gson/src/main/java/com/google/gson/Cache.java @@ -40,12 +40,4 @@ interface Cache { * @return the cached value for the given {@code key} */ V getElement(K key); - - /** - * Removes the value from the cache for the given key. - * - * @param key the key identifying the value to remove - * @return the value for the given {@code key} - */ - V removeElement(K key); } diff --git a/gson/src/main/java/com/google/gson/FieldAttributes.java b/gson/src/main/java/com/google/gson/FieldAttributes.java index 1df8f2ff..6710bb82 100644 --- a/gson/src/main/java/com/google/gson/FieldAttributes.java +++ b/gson/src/main/java/com/google/gson/FieldAttributes.java @@ -17,8 +17,6 @@ package com.google.gson; import com.google.gson.internal.$Gson$Preconditions; -import com.google.gson.internal.$Gson$Types; - import com.google.gson.internal.Pair; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -50,7 +48,6 @@ public final class FieldAttributes { private final boolean isSynthetic; private final int modifiers; private final String name; - private final Type resolvedType; // Fields used for lazy initialization private Type genericType; @@ -60,16 +57,14 @@ public final class FieldAttributes { * Constructs a Field Attributes object from the {@code f}. * * @param f the field to pull attributes from - * @param declaringType The type in which the field is declared */ - FieldAttributes(Class declaringClazz, Field f, Type declaringType) { + FieldAttributes(Class declaringClazz, Field f) { this.declaringClazz = $Gson$Preconditions.checkNotNull(declaringClazz); this.name = f.getName(); this.declaredType = f.getType(); this.isSynthetic = f.isSynthetic(); this.modifiers = f.getModifiers(); this.field = f; - this.resolvedType = getTypeInfoForField(f, declaringType); } private static int getMaxCacheSize() { @@ -121,7 +116,7 @@ public final class FieldAttributes { } /** - * Returns the {@code Class} object that was declared for this field. + * Returns the {@code Class} object that was declared for this field. * *

For example, assume the following class definition: *

@@ -185,16 +180,6 @@ public final class FieldAttributes {
     return (modifiers & modifier) != 0;
   }
 
-  /**
-   * This is exposed internally only for the removing synthetic fields from the JSON output.
-   *
-   * @throws IllegalAccessException
-   * @throws IllegalArgumentException
-   */
-  void set(Object instance, Object value) throws IllegalAccessException {
-    field.set(instance, value);
-  }
-
   /**
    * This is exposed internally only for the removing synthetic fields from the JSON output.
    *
@@ -223,10 +208,6 @@ public final class FieldAttributes {
     return field;
   }
 
-  Type getResolvedType() {
-    return resolvedType;
-  }
-
   @SuppressWarnings("unchecked")
   private static  T getAnnotationFromArray(
       Collection annotations, Class annotation) {
@@ -237,21 +218,4 @@ public final class FieldAttributes {
     }
     return null;
   }
-
-  /**
-   * Evaluates the "actual" type for the field.  If the field is a "TypeVariable" or has a
-   * "TypeVariable" in a parameterized type then it evaluates the real type.
-   *
-   * @param f the actual field object to retrieve the type from
-   * @param typeDefiningF the type that contains the field {@code f}
-   * @return the type information for the field
-   */
-  static Type getTypeInfoForField(Field f, Type typeDefiningF) {
-    Class rawType = $Gson$Types.getRawType(typeDefiningF);
-    if (!f.getDeclaringClass().isAssignableFrom(rawType)) {
-      // this field is unrelated to the type; the user probably omitted type information
-      return f.getGenericType();
-    }
-    return $Gson$Types.resolve(typeDefiningF, rawType, f.getGenericType());
-  }
 }
diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java
index 2237bd12..57171d55 100644
--- a/gson/src/main/java/com/google/gson/Gson.java
+++ b/gson/src/main/java/com/google/gson/Gson.java
@@ -111,7 +111,7 @@ public final class Gson {
   static final SyntheticFieldExclusionStrategy DEFAULT_SYNTHETIC_FIELD_EXCLUSION_STRATEGY =
       new SyntheticFieldExclusionStrategy(true);
   static final ModifierBasedExclusionStrategy DEFAULT_MODIFIER_BASED_EXCLUSION_STRATEGY =
-      new ModifierBasedExclusionStrategy(new int[] { Modifier.TRANSIENT, Modifier.STATIC });
+      new ModifierBasedExclusionStrategy(Modifier.TRANSIENT, Modifier.STATIC);
   static final FieldNamingStrategy2 DEFAULT_NAMING_POLICY =
       new SerializedNameAnnotationInterceptingNamingPolicy(new JavaFieldNamingPolicy());
 
@@ -209,20 +209,20 @@ public final class Gson {
         = new ReflectiveTypeAdapterFactory(constructorConstructor) {
       @Override
       public String getFieldName(Class declaringClazz, Field f, Type declaredType) {
-        return fieldNamingPolicy.translateName(new FieldAttributes(declaringClazz, f, declaredType));
+        return fieldNamingPolicy.translateName(new FieldAttributes(declaringClazz, f));
       }
       @Override
       public boolean serializeField(Class declaringClazz, Field f, Type declaredType) {
         ExclusionStrategy strategy = Gson.this.serializationExclusionStrategy;
         return !strategy.shouldSkipClass(f.getType())
-            && !strategy.shouldSkipField(new FieldAttributes(declaringClazz, f, declaredType));
+            && !strategy.shouldSkipField(new FieldAttributes(declaringClazz, f));
       }
 
       @Override
       public boolean deserializeField(Class declaringClazz, Field f, Type declaredType) {
         ExclusionStrategy strategy = Gson.this.deserializationExclusionStrategy;
         return !strategy.shouldSkipClass(f.getType())
-            && !strategy.shouldSkipField(new FieldAttributes(declaringClazz, f, declaredType));
+            && !strategy.shouldSkipField(new FieldAttributes(declaringClazz, f));
       }
     };
 
@@ -254,7 +254,7 @@ public final class Gson {
       builder.factory(factory);
     }
 
-    builder.factory(new GsonToMiniGsonTypeAdapterFactory(this, serializers, deserializers, serializeNulls))
+    builder.factory(new GsonToMiniGsonTypeAdapterFactory(this, serializers, deserializers))
         .factory(TypeAdapters.URL_FACTORY)
         .factory(TypeAdapters.URI_FACTORY)
         .factory(TypeAdapters.UUID_FACTORY)
@@ -685,7 +685,7 @@ public final class Gson {
    */
   public  T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException {
     JsonReader jsonReader = new JsonReader(json);
-    T object = this.fromJson(jsonReader, typeOfT);
+    T object = fromJson(jsonReader, typeOfT);
     assertFullConsumption(object, jsonReader);
     return object;
   }
diff --git a/gson/src/main/java/com/google/gson/GsonToMiniGsonTypeAdapterFactory.java b/gson/src/main/java/com/google/gson/GsonToMiniGsonTypeAdapterFactory.java
index 1b700027..086619f2 100644
--- a/gson/src/main/java/com/google/gson/GsonToMiniGsonTypeAdapterFactory.java
+++ b/gson/src/main/java/com/google/gson/GsonToMiniGsonTypeAdapterFactory.java
@@ -30,15 +30,12 @@ final class GsonToMiniGsonTypeAdapterFactory implements TypeAdapter.Factory {
   private final ParameterizedTypeHandlerMap> deserializers;
   private final JsonDeserializationContext deserializationContext;
   private final JsonSerializationContext serializationContext;
-  private final boolean serializeNulls;
 
   public GsonToMiniGsonTypeAdapterFactory(final Gson gson,
       ParameterizedTypeHandlerMap> serializers,
-      ParameterizedTypeHandlerMap> deserializers,
-      boolean serializeNulls) {
+      ParameterizedTypeHandlerMap> deserializers) {
     this.serializers = serializers;
     this.deserializers = deserializers;
-    this.serializeNulls = serializeNulls;
 
     this.deserializationContext = new JsonDeserializationContext() {
       public  T deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
diff --git a/gson/src/main/java/com/google/gson/JsonArray.java b/gson/src/main/java/com/google/gson/JsonArray.java
index 2e1f5501..1192b8c8 100644
--- a/gson/src/main/java/com/google/gson/JsonArray.java
+++ b/gson/src/main/java/com/google/gson/JsonArray.java
@@ -19,7 +19,6 @@ package com.google.gson;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -74,13 +73,6 @@ public final class JsonArray extends JsonElement implements Iterable extends LinkedHashMap implements Cache {
     return get(key);
   }
 
-  public synchronized V removeElement(K key) {
-    return remove(key);
-  }
-
   @Override
   protected boolean removeEldestEntry(Map.Entry entry) {
     return size() > maxCapacity;
diff --git a/gson/src/main/java/com/google/gson/internal/ParameterizedTypeHandlerMap.java b/gson/src/main/java/com/google/gson/internal/ParameterizedTypeHandlerMap.java
index 5ff14ea1..220c1dda 100644
--- a/gson/src/main/java/com/google/gson/internal/ParameterizedTypeHandlerMap.java
+++ b/gson/src/main/java/com/google/gson/internal/ParameterizedTypeHandlerMap.java
@@ -128,37 +128,6 @@ public final class ParameterizedTypeHandlerMap {
     }
   }
 
-  public synchronized void register(ParameterizedTypeHandlerMap other) {
-    if (!modifiable) {
-      throw new IllegalStateException("Attempted to modify an unmodifiable map.");
-    }
-    for (Map.Entry entry : other.userMap.entrySet()) {
-      register(entry.getKey(), entry.getValue(), false);
-    }
-    for (Map.Entry entry : other.systemMap.entrySet()) {
-      register(entry.getKey(), entry.getValue(), true);
-    }
-    // Quite important to traverse the typeHierarchyList from stack bottom first since
-    // we want to register the handlers in the same order to preserve priority order
-    for (int i = other.userTypeHierarchyList.size()-1; i >= 0; --i) {
-      Pair, T> entry = other.userTypeHierarchyList.get(i);
-      registerForTypeHierarchy(entry, false);
-    }
-    for (int i = other.systemTypeHierarchyList.size()-1; i >= 0; --i) {
-      Pair, T> entry = other.systemTypeHierarchyList.get(i);
-      registerForTypeHierarchy(entry, true);
-    }
-  }
-
-  public synchronized void registerIfAbsent(Type typeOfT, T value) {
-    if (!modifiable) {
-      throw new IllegalStateException("Attempted to modify an unmodifiable map.");
-    }
-    if (!userMap.containsKey(typeOfT)) {
-      register(typeOfT, value, false);
-    }
-  }
-
   public synchronized ParameterizedTypeHandlerMap makeUnmodifiable() {
     modifiable = false;
     return this;
diff --git a/gson/src/main/java/com/google/gson/internal/Streams.java b/gson/src/main/java/com/google/gson/internal/Streams.java
index 9a558fb6..731a5027 100644
--- a/gson/src/main/java/com/google/gson/internal/Streams.java
+++ b/gson/src/main/java/com/google/gson/internal/Streams.java
@@ -121,11 +121,6 @@ public final class Streams {
     } else if (element.isJsonArray()) {
       writer.beginArray();
       for (JsonElement e : element.getAsJsonArray()) {
-        /* always print null when its parent element is an array! */
-        if (e.isJsonNull()) {
-          writer.nullValue();
-          continue;
-        }
         write(e, writer);
       }
       writer.endArray();
diff --git a/gson/src/test/java/com/google/gson/DisjunctionExclusionStrategyTest.java b/gson/src/test/java/com/google/gson/DisjunctionExclusionStrategyTest.java
index 5dfd9630..2548d030 100644
--- a/gson/src/test/java/com/google/gson/DisjunctionExclusionStrategyTest.java
+++ b/gson/src/test/java/com/google/gson/DisjunctionExclusionStrategyTest.java
@@ -35,7 +35,7 @@ public class DisjunctionExclusionStrategyTest extends TestCase {
   
   private static final Class CLAZZ = String.class;
   private static final FieldAttributes FIELD =
-    new FieldAttributes(CLAZZ, CLAZZ.getFields()[0], CLAZZ);
+    new FieldAttributes(CLAZZ, CLAZZ.getFields()[0]);
 
   public void testBadInstantiation() throws Exception {
     try {
diff --git a/gson/src/test/java/com/google/gson/ExposeAnnotationExclusionStrategyTest.java b/gson/src/test/java/com/google/gson/ExposeAnnotationExclusionStrategyTest.java
index 0dcfedf4..b915b058 100644
--- a/gson/src/test/java/com/google/gson/ExposeAnnotationExclusionStrategyTest.java
+++ b/gson/src/test/java/com/google/gson/ExposeAnnotationExclusionStrategyTest.java
@@ -75,7 +75,7 @@ public class ExposeAnnotationExclusionStrategyTest extends TestCase {
   
   private static FieldAttributes createFieldAttributes(String fieldName) throws Exception {
     Field f = MockObject.class.getField(fieldName);
-    return new FieldAttributes(MockObject.class, f, MockObject.class);
+    return new FieldAttributes(MockObject.class, f);
   }
   
   @SuppressWarnings("unused")
diff --git a/gson/src/test/java/com/google/gson/FieldAttributesTest.java b/gson/src/test/java/com/google/gson/FieldAttributesTest.java
index 9e29f0db..af03f314 100644
--- a/gson/src/test/java/com/google/gson/FieldAttributesTest.java
+++ b/gson/src/test/java/com/google/gson/FieldAttributesTest.java
@@ -36,12 +36,12 @@ public class FieldAttributesTest extends TestCase {
   @Override
   protected void setUp() throws Exception {
     super.setUp();
-    fieldAttributes = new FieldAttributes(Foo.class, Foo.class.getField("bar"), Foo.class);
+    fieldAttributes = new FieldAttributes(Foo.class, Foo.class.getField("bar"));
   }
 
   public void testNullField() throws Exception {
     try {
-      new FieldAttributes(Foo.class, null, Foo.class);
+      new FieldAttributes(Foo.class, null);
       fail("Field parameter can not be null");
     } catch (NullPointerException expected) { }
   }
diff --git a/gson/src/test/java/com/google/gson/FieldNamingStrategy2AdapterTest.java b/gson/src/test/java/com/google/gson/FieldNamingStrategy2AdapterTest.java
index 639a47ee..f215a298 100644
--- a/gson/src/test/java/com/google/gson/FieldNamingStrategy2AdapterTest.java
+++ b/gson/src/test/java/com/google/gson/FieldNamingStrategy2AdapterTest.java
@@ -34,7 +34,7 @@ public class FieldNamingStrategy2AdapterTest extends TestCase {
     FieldNamingStrategy2 adapter =
         new FieldNamingStrategy2Adapter(new UpperCaseNamingStrategy());
     assertEquals(expectedFieldName, adapter.translateName(
-        new FieldAttributes(String.class, field, String.class)));
+        new FieldAttributes(String.class, field)));
   }
   
   private static class UpperCaseNamingStrategy implements FieldNamingStrategy {
diff --git a/gson/src/test/java/com/google/gson/InnerClassExclusionStrategyTest.java b/gson/src/test/java/com/google/gson/InnerClassExclusionStrategyTest.java
index 1ba8f51e..d5e8a2bc 100644
--- a/gson/src/test/java/com/google/gson/InnerClassExclusionStrategyTest.java
+++ b/gson/src/test/java/com/google/gson/InnerClassExclusionStrategyTest.java
@@ -46,7 +46,7 @@ public class InnerClassExclusionStrategyTest extends TestCase {
 
   public void testExcludeInnerClassField() throws Exception {
     Field f = getClass().getField("innerClass");
-    assertTrue(strategy.shouldSkipField(new FieldAttributes(getClass(), f, getClass())));
+    assertTrue(strategy.shouldSkipField(new FieldAttributes(getClass(), f)));
   }
 
   public void testIncludeStaticNestedClassObject() throws Exception {
@@ -56,7 +56,7 @@ public class InnerClassExclusionStrategyTest extends TestCase {
 
   public void testIncludeStaticNestedClassField() throws Exception {
     Field f = getClass().getField("staticNestedClass");
-    assertFalse(strategy.shouldSkipField(new FieldAttributes(getClass(), f, getClass())));
+    assertFalse(strategy.shouldSkipField(new FieldAttributes(getClass(), f)));
   }
 
   class InnerClass {
diff --git a/gson/src/test/java/com/google/gson/JavaFieldNamingPolicyTest.java b/gson/src/test/java/com/google/gson/JavaFieldNamingPolicyTest.java
index 7c91e2cd..db19ed0e 100644
--- a/gson/src/test/java/com/google/gson/JavaFieldNamingPolicyTest.java
+++ b/gson/src/test/java/com/google/gson/JavaFieldNamingPolicyTest.java
@@ -34,7 +34,7 @@ public class JavaFieldNamingPolicyTest extends TestCase {
   }
 
   public void testFieldNamingPolicy() throws Exception {
-    FieldAttributes f = new FieldAttributes(String.class, String.class.getFields()[0], String.class);
+    FieldAttributes f = new FieldAttributes(String.class, String.class.getFields()[0]);
     assertEquals(f.getName(), namingPolicy.translateName(f));
   }
 
diff --git a/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java b/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java
index 6eff2ee3..ea1fa708 100644
--- a/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java
+++ b/gson/src/test/java/com/google/gson/ParamterizedTypeFixtures.java
@@ -155,7 +155,17 @@ public class ParamterizedTypeFixtures {
       Type genericClass = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
       Class rawType = $Gson$Types.getRawType(genericClass);
       String className = rawType.getSimpleName();
-      T value = (T) json.getAsJsonObject().get(className).getAsObject();
+      JsonElement jsonElement = json.getAsJsonObject().get(className);
+
+      T value;
+      if (genericClass == Integer.class) {
+        value = (T) Integer.valueOf(jsonElement.getAsInt());
+      } else if (genericClass == String.class) {
+        value = (T) jsonElement.getAsString();
+      } else {
+        value = (T) jsonElement;
+      }
+
       if (Primitives.isPrimitive(genericClass)) {
         PrimitiveTypeAdapter typeAdapter = new PrimitiveTypeAdapter();
         value = (T) typeAdapter.adaptType(value, rawType);
diff --git a/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java b/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java
index e73655a4..57711028 100644
--- a/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java
+++ b/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java
@@ -39,7 +39,7 @@ public class SerializedNameAnnotationInterceptingNamingPolicyTest extends TestCa
   public void testFieldWithAnnotation() throws Exception {
     String fieldName = "fieldWithAnnotation";
     FieldAttributes f = new FieldAttributes(
-        SomeObject.class, SomeObject.class.getField(fieldName), SomeObject.class);
+        SomeObject.class, SomeObject.class.getField(fieldName));
 
     assertFalse(ANNOTATED_FIELD_NAME.equals(fieldName));
     assertEquals(ANNOTATED_FIELD_NAME, policy.translateName(f));
@@ -48,7 +48,7 @@ public class SerializedNameAnnotationInterceptingNamingPolicyTest extends TestCa
   public void testFieldWithoutAnnotation() throws Exception {
     String fieldName = "fieldWithoutAnnotation";
     FieldAttributes f = new FieldAttributes(
-        SomeObject.class, SomeObject.class.getField(fieldName), SomeObject.class);
+        SomeObject.class, SomeObject.class.getField(fieldName));
 
     assertEquals(fieldName, policy.translateName(f));
   }
diff --git a/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java b/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java
index 95f9e381..e0844d87 100644
--- a/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java
+++ b/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java
@@ -43,7 +43,7 @@ public class VersionExclusionStrategyTest extends TestCase {
     VersionExclusionStrategy strategy = new VersionExclusionStrategy(VERSION);
     assertFalse(strategy.shouldSkipClass(clazz));
 
-    FieldAttributes fieldAttributes = new FieldAttributes(clazz, f, clazz);
+    FieldAttributes fieldAttributes = new FieldAttributes(clazz, f);
     assertFalse(strategy.shouldSkipField(fieldAttributes));
   }
 
@@ -53,7 +53,7 @@ public class VersionExclusionStrategyTest extends TestCase {
     VersionExclusionStrategy strategy = new VersionExclusionStrategy(VERSION + 1);
     assertFalse(strategy.shouldSkipClass(clazz));
     
-    FieldAttributes fieldAttributes = new FieldAttributes(clazz, f, clazz);
+    FieldAttributes fieldAttributes = new FieldAttributes(clazz, f);
     assertFalse(strategy.shouldSkipField(fieldAttributes));
   }
 
@@ -63,7 +63,7 @@ public class VersionExclusionStrategyTest extends TestCase {
     VersionExclusionStrategy strategy = new VersionExclusionStrategy(VERSION - 1);
     assertTrue(strategy.shouldSkipClass(clazz));
     
-    FieldAttributes fieldAttributes = new FieldAttributes(clazz, f, clazz);
+    FieldAttributes fieldAttributes = new FieldAttributes(clazz, f);
     assertTrue(strategy.shouldSkipField(fieldAttributes));
   }
 
diff --git a/gson/src/test/java/com/google/gson/functional/ParameterizedTypesTest.java b/gson/src/test/java/com/google/gson/functional/ParameterizedTypesTest.java
index 2fe1c76c..6fa856df 100644
--- a/gson/src/test/java/com/google/gson/functional/ParameterizedTypesTest.java
+++ b/gson/src/test/java/com/google/gson/functional/ParameterizedTypesTest.java
@@ -127,7 +127,7 @@ public class ParameterizedTypesTest extends TestCase {
     MyParameterizedType src = new MyParameterizedType(10);
     String json = MyParameterizedTypeAdapter.getExpectedJson(src);
     MyParameterizedType intTarget = gson.fromJson(json, ptIntegerType);
-    assertEquals(10, ((Number)intTarget.value).intValue());
+    assertEquals(10, intTarget.value.intValue());
 
     MyParameterizedType srcStr = new MyParameterizedType("abc");
     json = MyParameterizedTypeAdapter.getExpectedJson(srcStr);