diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index dd7d160f..61b6f123 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -319,7 +319,6 @@ public final class GsonBuilder { * {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces. * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern */ - @SuppressWarnings("unchecked") public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { Preconditions.checkArgument(typeAdapter instanceof JsonSerializer || typeAdapter instanceof JsonDeserializer || typeAdapter instanceof InstanceCreator); diff --git a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java index cb998d55..9d1e5bc9 100644 --- a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java @@ -144,6 +144,10 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor { @SuppressWarnings("unchecked") public boolean visitUsingCustomHandler(Object obj, Type objType) { JsonSerializer serializer = serializers.getHandlerFor(objType); + if (serializer == null && obj != null) { + serializer = serializers.getHandlerFor(obj.getClass()); + } + if (serializer != null) { if (obj == null) { assignToRoot(JsonNull.createJsonNull()); diff --git a/gson/src/main/java/com/google/gson/ObjectNavigator.java b/gson/src/main/java/com/google/gson/ObjectNavigator.java index 727c3f06..dd82c2cb 100644 --- a/gson/src/main/java/com/google/gson/ObjectNavigator.java +++ b/gson/src/main/java/com/google/gson/ObjectNavigator.java @@ -108,15 +108,20 @@ final class ObjectNavigator { try { if (objTypeInfo.isArray()) { visitor.visitArray(objectToVisit, objType); - } else if (objTypeInfo.getActualType() == Object.class) { + } else if (objTypeInfo.getActualType() == Object.class + && isPrimitiveOrString(objectToVisit)) { + // TODO(Joel): this is only used for deserialization of "primitves" + // we should rethink this!!! visitor.visitPrimitive(objectToVisit); objectToVisit = visitor.getTarget(); } else { visitor.startVisitingObject(objectToVisit); // For all classes in the inheritance hierarchy (including the current class), // visit all fields - for (Class curr = objTypeInfo.getRawClass(); - curr != null && !curr.equals(Object.class); curr = curr.getSuperclass()) { + Class topLevelClass = (objTypeInfo.getRawClass() == Object.class) + ? objectToVisit.getClass() : objTypeInfo.getRawClass(); + for (Class curr = topLevelClass; curr != null && !curr.equals(Object.class); + curr = curr.getSuperclass()) { if (!curr.isSynthetic()) { navigateClassFields(objectToVisit, curr, visitor); } @@ -128,6 +133,12 @@ final class ObjectNavigator { } } + private boolean isPrimitiveOrString(Object objectToVisit) { + Class realClazz = objectToVisit.getClass(); + return realClazz == Object.class || realClazz == String.class + || Primitives.unwrap(realClazz).isPrimitive(); + } + private void navigateClassFields(Object obj, Class clazz, Visitor visitor) { Field[] fields = clazz.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); @@ -138,7 +149,7 @@ final class ObjectNavigator { TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objType); Type actualTypeOfField = fieldTypeInfo.getActualType(); boolean visitedWithCustomHandler = - visitor.visitFieldUsingCustomHandler(f, actualTypeOfField, obj); + visitor.visitFieldUsingCustomHandler(f, actualTypeOfField, obj); if (!visitedWithCustomHandler) { if (fieldTypeInfo.isArray()) { visitor.visitArrayField(f, actualTypeOfField, obj); diff --git a/gson/src/main/java/com/google/gson/TypeInfoFactory.java b/gson/src/main/java/com/google/gson/TypeInfoFactory.java index 2bcdb82e..deb88a2f 100644 --- a/gson/src/main/java/com/google/gson/TypeInfoFactory.java +++ b/gson/src/main/java/com/google/gson/TypeInfoFactory.java @@ -55,7 +55,6 @@ final class TypeInfoFactory { return new TypeInfo(actualType); } - @SuppressWarnings("unchecked") private static Type getActualType( Type typeToEvaluate, Type parentType, Class rawParentClass) { if (typeToEvaluate instanceof Class) { diff --git a/gson/src/main/java/com/google/gson/TypeInfoMap.java b/gson/src/main/java/com/google/gson/TypeInfoMap.java index 82f4b19f..ea8eb07b 100644 --- a/gson/src/main/java/com/google/gson/TypeInfoMap.java +++ b/gson/src/main/java/com/google/gson/TypeInfoMap.java @@ -31,7 +31,6 @@ final class TypeInfoMap { private final Type keyType; private final Type valueType; - @SuppressWarnings("unchecked") public TypeInfoMap(Type mapType) { if (mapType instanceof Class && Properties.class.isAssignableFrom((Class) mapType)) { keyType = String.class; diff --git a/gson/src/main/java/com/google/gson/TypeUtils.java b/gson/src/main/java/com/google/gson/TypeUtils.java index c8c03d65..acda71a6 100644 --- a/gson/src/main/java/com/google/gson/TypeUtils.java +++ b/gson/src/main/java/com/google/gson/TypeUtils.java @@ -40,7 +40,6 @@ final class TypeUtils { * * TypeUtils.getActualTypeForFirstTypeVariable(fooType) will return Integer.class. */ - @SuppressWarnings("unchecked") static Type getActualTypeForFirstTypeVariable(Type type) { if (type instanceof Class) { return Object.class; @@ -54,7 +53,6 @@ final class TypeUtils { } } - @SuppressWarnings("unchecked") static boolean isArray(Type type) { if (type instanceof Class) { return ((Class)type).isArray(); @@ -68,7 +66,6 @@ final class TypeUtils { /** * This method returns the actual raw class associated with the specified type. */ - @SuppressWarnings("unchecked") static Class toRawClass(Type type) { if (type instanceof Class) { return (Class) type; diff --git a/gson/src/main/java/com/google/gson/reflect/TypeToken.java b/gson/src/main/java/com/google/gson/reflect/TypeToken.java index 4ab1425f..c9eef2f1 100644 --- a/gson/src/main/java/com/google/gson/reflect/TypeToken.java +++ b/gson/src/main/java/com/google/gson/reflect/TypeToken.java @@ -85,7 +85,6 @@ public abstract class TypeToken { /** * Gets type from super class's type parameter. */ - @SuppressWarnings("unchecked") static Type getSuperclassTypeParameter(Class subclass) { Type superclass = subclass.getGenericSuperclass(); if (superclass instanceof Class) { @@ -155,7 +154,6 @@ public abstract class TypeToken { /** * Check if this type is assignable from the given Type. */ - @SuppressWarnings("unchecked") public boolean isAssignableFrom(Type from) { if (from == null) { return false; @@ -190,7 +188,6 @@ public abstract class TypeToken { * Private helper function that performs some assignability checks for * the provided GenericArrayType. */ - @SuppressWarnings("unchecked") private static boolean isAssignableFrom(Type from, GenericArrayType to) { Type toGenericComponentType = to.getGenericComponentType(); if (toGenericComponentType instanceof ParameterizedType) { @@ -216,7 +213,6 @@ public abstract class TypeToken { * Private recursive helper function to actually do the type-safe checking * of assignability. */ - @SuppressWarnings("unchecked") private static boolean isAssignableFrom(Type from, ParameterizedType to, Map typeVarMap) { @@ -293,7 +289,6 @@ public abstract class TypeToken { * Checks if two types are the same or are equivalent under a variable mapping * given in the type map that was provided. */ - @SuppressWarnings("unchecked") private static boolean matches(Type from, Type to, Map typeMap) { if (to.equals(from)) return true; diff --git a/gson/src/test/java/com/google/gson/ExposeAnnotationBasedExclusionStrategyTest.java b/gson/src/test/java/com/google/gson/ExposeAnnotationBasedExclusionStrategyTest.java index 1f63f95e..556d7506 100644 --- a/gson/src/test/java/com/google/gson/ExposeAnnotationBasedExclusionStrategyTest.java +++ b/gson/src/test/java/com/google/gson/ExposeAnnotationBasedExclusionStrategyTest.java @@ -51,7 +51,6 @@ public class ExposeAnnotationBasedExclusionStrategyTest extends TestCase { assertFalse(strategy.shouldSkipField(f)); } - @SuppressWarnings("unused") private static class MockObject { @Expose public final int exposedField = 0; diff --git a/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java b/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java index a0144a58..bb9cf92b 100644 --- a/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java +++ b/gson/src/test/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicyTest.java @@ -53,7 +53,6 @@ public class SerializedNameAnnotationInterceptingNamingPolicyTest extends TestCa assertEquals(fieldName, policy.translateName(f)); } - @SuppressWarnings("unused") private static class SomeObject { @SerializedName(ANNOTATED_FIELD_NAME) public final int fieldWithAnnotation = 1; public final int fieldWithoutAnnotation = 1; diff --git a/gson/src/test/java/com/google/gson/TypeInfoFactoryTest.java b/gson/src/test/java/com/google/gson/TypeInfoFactoryTest.java index 26155307..913154b8 100644 --- a/gson/src/test/java/com/google/gson/TypeInfoFactoryTest.java +++ b/gson/src/test/java/com/google/gson/TypeInfoFactoryTest.java @@ -223,7 +223,6 @@ public class TypeInfoFactoryTest extends TestCase { assertEquals(List[].class, typeInfo.getRawClass()); } - @SuppressWarnings("unused") private static class ObjectWithDifferentFields { public static enum TestEnum { TEST_1, TEST_2; diff --git a/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java b/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java index d044eb34..f023b73f 100644 --- a/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java +++ b/gson/src/test/java/com/google/gson/VersionExclusionStrategyTest.java @@ -66,7 +66,7 @@ public class VersionExclusionStrategyTest extends TestCase { @Since(VERSION) private static class MockObject { - @SuppressWarnings("unused") + @Since(VERSION) public final int someField = 0; } diff --git a/gson/src/test/java/com/google/gson/functional/ArrayTest.java b/gson/src/test/java/com/google/gson/functional/ArrayTest.java index 054dbeaf..74980722 100644 --- a/gson/src/test/java/com/google/gson/functional/ArrayTest.java +++ b/gson/src/test/java/com/google/gson/functional/ArrayTest.java @@ -21,12 +21,14 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import com.google.gson.common.MoreAsserts; import com.google.gson.common.TestTypes.BagOfPrimitives; +import com.google.gson.common.TestTypes.ClassWithObjects; import com.google.gson.common.TestTypes.CrazyLongTypeAdapter; import com.google.gson.reflect.TypeToken; import junit.framework.TestCase; import java.lang.reflect.Type; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; @@ -179,4 +181,50 @@ public class ArrayTest extends TestCase { assertEquals(1, deserializedValue.length); assertEquals(value[0], deserializedValue[0]); } + + public void testArrayOfPrimitivesAsObjectsSerialization() throws Exception { + Object[] objs = new Object[]{1, "abc", 0.3f, 5L}; + String json = gson.toJson(objs); + assertTrue(json.contains("abc")); + assertTrue(json.contains("0.3")); + assertTrue(json.contains("5")); + } + + public void testArrayOfPrimitivesAsObjectsDeserialization() throws Exception { + String json = "[1,'abc',0.3,5]"; + Object[] objs = gson.fromJson(json, Object[].class); + assertEquals(1, objs[0]); + assertEquals("abc", objs[1]); + assertEquals(new BigDecimal("0.3"), objs[2]); + assertEquals(5, objs[3]); + } + + public void testArrayOfObjectsWithoutTypeInfoDeserialization() throws Exception { + String json = "[1,'abc',{a:1},5]"; + try { + gson.fromJson(json, Object[].class); + } catch (JsonParseException expected) { + } + } + + public void testArrayWithoutTypeInfoDeserialization() throws Exception { + String json = "[1,'abc',[1,2],5]"; + try { + gson.fromJson(json, Object[].class); + } catch (JsonParseException expected) { + } + } + + public void testObjectArrayWithNonPrimitivesSerializaiton() throws Exception { + ClassWithObjects classWithObjects = new ClassWithObjects(); + BagOfPrimitives bagOfPrimitives = new BagOfPrimitives(); + String classWithObjectsJson = gson.toJson(classWithObjects); + String bagOfPrimitivesJson = gson.toJson(bagOfPrimitives); + + Object[] objects = new Object[] { classWithObjects, bagOfPrimitives }; + String json = gson.toJson(objects); + + assertTrue(json.contains(classWithObjectsJson)); + assertTrue(json.contains(bagOfPrimitivesJson)); + } } diff --git a/gson/src/test/java/com/google/gson/functional/CollectionTest.java b/gson/src/test/java/com/google/gson/functional/CollectionTest.java index 6d812bdb..ef625121 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -283,7 +283,7 @@ public class CollectionTest extends TestCase { private static class ObjectWithWildcardCollection { private final Collection collection; - @SuppressWarnings({ "unchecked", "unused" }) + @SuppressWarnings("unchecked") public ObjectWithWildcardCollection() { this(Collections.EMPTY_LIST); } @@ -300,7 +300,6 @@ public class CollectionTest extends TestCase { private static class Entry { int value; // For use by Gson - @SuppressWarnings("unused") Entry() { this(10); } diff --git a/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java b/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java index 2dccf4b6..91a784bc 100755 --- a/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java +++ b/gson/src/test/java/com/google/gson/functional/ConcurrencyTest.java @@ -120,8 +120,7 @@ public class ConcurrencyTest extends TestCase { finishedLatch.await(); assertFalse(failed.get()); } - - @SuppressWarnings("unused") + private static class MyObject { String a; String b; diff --git a/gson/src/test/java/com/google/gson/functional/CustomDeserializerTest.java b/gson/src/test/java/com/google/gson/functional/CustomDeserializerTest.java index b8083d6f..a3f337e1 100644 --- a/gson/src/test/java/com/google/gson/functional/CustomDeserializerTest.java +++ b/gson/src/test/java/com/google/gson/functional/CustomDeserializerTest.java @@ -65,7 +65,6 @@ public class CustomDeserializerTest extends TestCase { private static class DataHolder { private final String data; - @SuppressWarnings("unused") public DataHolder() { throw new IllegalStateException(); } @@ -82,7 +81,6 @@ public class CustomDeserializerTest extends TestCase { private static class DataHolderWrapper { private final DataHolder wrappedData; - @SuppressWarnings("unused") public DataHolderWrapper() { this(new DataHolder(DEFAULT_VALUE)); } diff --git a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java index a173eaca..88ca359d 100644 --- a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java @@ -289,7 +289,6 @@ public class DefaultTypeAdaptersTest extends TestCase { private static class ClassWithBigDecimal { BigDecimal value; - @SuppressWarnings("unused") ClassWithBigDecimal() { } ClassWithBigDecimal(String value) { this.value = new BigDecimal(value); @@ -301,7 +300,6 @@ public class DefaultTypeAdaptersTest extends TestCase { private static class ClassWithBigInteger { BigInteger value; - @SuppressWarnings("unused") ClassWithBigInteger() { } ClassWithBigInteger(String value) { this.value = new BigInteger(value); diff --git a/gson/src/test/java/com/google/gson/functional/ExposeFieldsTest.java b/gson/src/test/java/com/google/gson/functional/ExposeFieldsTest.java index 40f580f7..96a89f7b 100644 --- a/gson/src/test/java/com/google/gson/functional/ExposeFieldsTest.java +++ b/gson/src/test/java/com/google/gson/functional/ExposeFieldsTest.java @@ -117,7 +117,6 @@ public class ExposeFieldsTest extends TestCase { @Expose(deserialize = false) final double d; @Expose(serialize = false, deserialize = false) final char e; - @SuppressWarnings("unused") ClassWithExposedFields() { this(null, null); } @@ -166,8 +165,7 @@ public class ExposeFieldsTest extends TestCase { private static class ClassWithInterfaceField { @Expose private final SomeInterface interfaceField; - - @SuppressWarnings("unused") + public ClassWithInterfaceField() { this(null); } diff --git a/gson/src/test/java/com/google/gson/functional/JsonTreeTest.java b/gson/src/test/java/com/google/gson/functional/JsonTreeTest.java index 195f6f99..85a6bd5e 100644 --- a/gson/src/test/java/com/google/gson/functional/JsonTreeTest.java +++ b/gson/src/test/java/com/google/gson/functional/JsonTreeTest.java @@ -75,7 +75,6 @@ public class JsonTreeTest extends TestCase { } private static class SubTypeOfBagOfPrimitives extends BagOfPrimitives { - @SuppressWarnings("unused") float f = 1.2F; public SubTypeOfBagOfPrimitives(long l, int i, boolean b, String string, float f) { super(l, i, b, string); diff --git a/gson/src/test/java/com/google/gson/functional/MapTest.java b/gson/src/test/java/com/google/gson/functional/MapTest.java index 6e084e0a..895602b8 100755 --- a/gson/src/test/java/com/google/gson/functional/MapTest.java +++ b/gson/src/test/java/com/google/gson/functional/MapTest.java @@ -172,7 +172,6 @@ public class MapTest extends TestCase { private static class MyParameterizedMap extends LinkedHashMap { private static final long serialVersionUID = 1L; - @SuppressWarnings("unused") int foo = 10; } @@ -249,7 +248,6 @@ public class MapTest extends TestCase { private static class MyMap extends LinkedHashMap { private static final long serialVersionUID = 1L; - @SuppressWarnings("unused") int foo = 10; } diff --git a/gson/src/test/java/com/google/gson/functional/NamingPolicyTest.java b/gson/src/test/java/com/google/gson/functional/NamingPolicyTest.java index 5fca249c..ef8a651a 100644 --- a/gson/src/test/java/com/google/gson/functional/NamingPolicyTest.java +++ b/gson/src/test/java/com/google/gson/functional/NamingPolicyTest.java @@ -81,8 +81,7 @@ public class NamingPolicyTest extends TestCase { actual = gson.toJson(target); assertEquals("{\"a\":3.0}", actual); } - - @SuppressWarnings("unused") + private static class ClassWithDuplicateFields { public Integer a; @SerializedName("a") public Double b; diff --git a/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java b/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java index fe9f1ffe..f2b94f97 100755 --- a/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java +++ b/gson/src/test/java/com/google/gson/functional/NullObjectAndFieldTest.java @@ -151,7 +151,6 @@ public class NullObjectAndFieldTest extends TestCase { private Long value; } - @SuppressWarnings("unused") private static class ClassWithMembers { String str; int[] array; diff --git a/gson/src/test/java/com/google/gson/functional/ObjectTest.java b/gson/src/test/java/com/google/gson/functional/ObjectTest.java index 9ccd4eb7..170beeca 100644 --- a/gson/src/test/java/com/google/gson/functional/ObjectTest.java +++ b/gson/src/test/java/com/google/gson/functional/ObjectTest.java @@ -16,10 +16,21 @@ package com.google.gson.functional; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import junit.framework.TestCase; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.InstanceCreator; -import com.google.gson.JsonParseException; import com.google.gson.common.TestTypes.ArrayOfObjects; import com.google.gson.common.TestTypes.BagOfPrimitiveWrappers; import com.google.gson.common.TestTypes.BagOfPrimitives; @@ -31,19 +42,6 @@ import com.google.gson.common.TestTypes.ClassWithTransientFields; import com.google.gson.common.TestTypes.Nested; import com.google.gson.common.TestTypes.PrimitiveArray; -import junit.framework.TestCase; - -import java.lang.reflect.Type; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - /** * Functional tests for Json serialization and deserialization of regular classes. * @@ -257,6 +255,22 @@ public class ObjectTest extends TestCase { assertTrue(target.sortedSetContains('a', 'b', 'c', 'd')); } + public void testArrayOfObjectsAsFields() throws Exception { + ClassWithObjects classWithObjects = new ClassWithObjects(); + BagOfPrimitives bagOfPrimitives = new BagOfPrimitives(); + String stringValue = "someStringValueInArray"; + String classWithObjectsJson = gson.toJson(classWithObjects); + String bagOfPrimitivesJson = gson.toJson(bagOfPrimitives); + + ClassWithArray classWithArray = new ClassWithArray( + new Object[] { stringValue, classWithObjects, bagOfPrimitives }); + String json = gson.toJson(classWithArray); + + assertTrue(json.contains(classWithObjectsJson)); + assertTrue(json.contains(bagOfPrimitivesJson)); + assertTrue(json.contains("\"" + stringValue + "\"")); + } + /** * Created in response to Issue 14: http://code.google.com/p/google-gson/issues/detail?id=14 */ @@ -350,8 +364,7 @@ public class ObjectTest extends TestCase { String json = gson.toJson(obj); assertTrue(json.contains("abc")); } - - @SuppressWarnings("unused") + private static class ClassWithObjectField { Object member; } @@ -378,7 +391,6 @@ public class ObjectTest extends TestCase { } private static class Parent { - @SuppressWarnings("unused") int value1 = 1; private class Child { int value2 = 2; @@ -392,7 +404,6 @@ public class ObjectTest extends TestCase { private SortedSet sortedSet; // For use by Gson - @SuppressWarnings("unused") ClassWithSubInterfacesOfCollection() { } @@ -485,7 +496,6 @@ public class ObjectTest extends TestCase { private static class SubTypeOfNested extends Nested { private final long value = 5; - @SuppressWarnings("unused") public SubTypeOfNested() { this(null, null); } @@ -569,39 +579,6 @@ public class ObjectTest extends TestCase { bag = gson.fromJson(json, BagOfPrimitives.class); assertEquals("true", bag.stringValue); } - - public void testArrayOfPrimitivesAsObjectsSerialization() { - Object[] objs = new Object[]{1, "abc", 0.3f, 5L}; - String json = gson.toJson(objs); - assertTrue(json.contains("abc")); - assertTrue(json.contains("0.3")); - assertTrue(json.contains("5")); - } - - public void testArrayOfPrimitivesAsObjectsDeserialization() { - String json = "[1,'abc',0.3,5]"; - Object[] objs = gson.fromJson(json, Object[].class); - assertEquals(1, objs[0]); - assertEquals("abc", objs[1]); - assertEquals(new BigDecimal("0.3"), objs[2]); - assertEquals(5, objs[3]); - } - - public void testArrayOfObjectsWithoutTypeInfoDeserialization() { - String json = "[1,'abc',{a:1},5]"; - try { - gson.fromJson(json, Object[].class); - } catch (JsonParseException expected) { - } - } - - public void testArrayWithoutTypeInfoDeserialization() { - String json = "[1,'abc',[1,2],5]"; - try { - gson.fromJson(json, Object[].class); - } catch (JsonParseException expected) { - } - } /** * Created to reproduce issue 140 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 bdf9532b..f59f3136 100644 --- a/gson/src/test/java/com/google/gson/functional/ParameterizedTypesTest.java +++ b/gson/src/test/java/com/google/gson/functional/ParameterizedTypesTest.java @@ -271,7 +271,6 @@ public class ParameterizedTypesTest extends TestCase { private final List listOfWildcardTypeParameters; private final List[] arrayOfListOfWildcardTypeParameters; - @SuppressWarnings("unused") public ObjectWithTypeVariables() { this(null, null, null, null, null, null); } @@ -387,7 +386,6 @@ public class ParameterizedTypesTest extends TestCase { C c; D d; E e; - @SuppressWarnings("unused") MultiParameters() { } MultiParameters(A a, B b, C c, D d, E e) { @@ -463,11 +461,9 @@ public class ParameterizedTypesTest extends TestCase { // Begin: tests to reproduce issue 103 private static class Quantity { - @SuppressWarnings("unused") int q = 10; } private static class MyQuantity extends Quantity { - @SuppressWarnings("unused") int q2 = 20; } private interface Measurable { diff --git a/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java b/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java index 196a0bae..6595d1e0 100644 --- a/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java +++ b/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java @@ -72,7 +72,6 @@ public class PerformanceTest extends TestCase { private static class ExceptionHolder { public final String message; public final String stackTrace; - @SuppressWarnings("unused") public ExceptionHolder() { this("", ""); } @@ -82,15 +81,14 @@ public class PerformanceTest extends TestCase { } } - @SuppressWarnings("unused") private static class CollectionEntry { final String name; final String value; - + CollectionEntry() { this(null, null); } - + CollectionEntry(String name, String value) { this.name = name; this.value = value;