From 2780a2a9bf5b0bf7eb6b14fc6ec27916c1c867fc Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Fri, 16 Sep 2011 06:03:16 +0000 Subject: [PATCH] Fixed eclipse warnings. --- gson/src/main/java/com/google/gson/Gson.java | 1 - .../main/java/com/google/gson/JsonDeserializationContext.java | 4 +--- .../java/com/google/gson/internal/ConstructorConstructor.java | 4 +++- .../java/com/google/gson/internal/bind/ArrayTypeAdapter.java | 2 ++ .../main/java/com/google/gson/internal/bind/Reflection.java | 1 + gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java | 2 ++ .../test/java/com/google/gson/functional/CollectionTest.java | 1 + 7 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java index b53f71a1..dc30e30d 100644 --- a/gson/src/main/java/com/google/gson/Gson.java +++ b/gson/src/main/java/com/google/gson/Gson.java @@ -730,7 +730,6 @@ public final class Gson { * @throws JsonSyntaxException if json is not a valid representation for an object of type typeOfT * @since 1.3 */ - @SuppressWarnings("unchecked") public T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException { if (json == null) { return null; diff --git a/gson/src/main/java/com/google/gson/JsonDeserializationContext.java b/gson/src/main/java/com/google/gson/JsonDeserializationContext.java index 578e6e89..da0e2dbb 100644 --- a/gson/src/main/java/com/google/gson/JsonDeserializationContext.java +++ b/gson/src/main/java/com/google/gson/JsonDeserializationContext.java @@ -36,7 +36,7 @@ public class JsonDeserializationContext { /** * TODO: remove this from the public API */ - @SuppressWarnings("unchecked") @Deprecated + @Deprecated public T construct(Type type) { throw new UnsupportedOperationException(); } @@ -57,12 +57,10 @@ public class JsonDeserializationContext { * @return An object of type typeOfT. * @throws JsonParseException if the parse tree does not contain expected data. */ - @SuppressWarnings("unchecked") public T deserialize(JsonElement json, Type typeOfT) throws JsonParseException { return gson.fromJson(json, typeOfT); } - @SuppressWarnings("unchecked") public T deserializeDefault(JsonElement json, Type typeOfT) throws JsonParseException { throw new UnsupportedOperationException(); } diff --git a/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java b/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java index 48696310..ef7ae630 100644 --- a/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java +++ b/gson/src/main/java/com/google/gson/internal/ConstructorConstructor.java @@ -156,9 +156,11 @@ public final class ConstructorConstructor { final Type type, final Class rawType) { return new ObjectConstructor() { private final UnsafeAllocator unsafeAllocator = UnsafeAllocator.create(); + @SuppressWarnings("unchecked") public T construct() { try { - return (T) unsafeAllocator.newInstance(rawType); + Object newInstance = unsafeAllocator.newInstance(rawType); + return (T) newInstance; } catch (Exception e) { throw new RuntimeException(("Unable to invoke no-args constructor for " + type + ". " + "Register an InstanceCreator with Gson for this type may fix this problem."), e); diff --git a/gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java b/gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java index 75ce5d25..a317026a 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java +++ b/gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java @@ -34,6 +34,7 @@ import com.google.gson.stream.JsonWriter; */ public final class ArrayTypeAdapter extends TypeAdapter { public static final Factory FACTORY = new Factory() { + @SuppressWarnings("unchecked") public TypeAdapter create(MiniGson context, TypeToken typeToken) { Type type = typeToken.getType(); if (!(type instanceof GenericArrayType || type instanceof Class && ((Class) type).isArray())) { @@ -78,6 +79,7 @@ public final class ArrayTypeAdapter extends TypeAdapter { return array; } + @SuppressWarnings("unchecked") @Override public void write(JsonWriter writer, Object array) throws IOException { if (array == null) { writer.nullValue(); // TODO: better policy here? diff --git a/gson/src/main/java/com/google/gson/internal/bind/Reflection.java b/gson/src/main/java/com/google/gson/internal/bind/Reflection.java index a901ad11..266bd22e 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/Reflection.java +++ b/gson/src/main/java/com/google/gson/internal/bind/Reflection.java @@ -22,6 +22,7 @@ final class Reflection { /** * Finds a compatible runtime type if it is more specific */ + @SuppressWarnings("unchecked") public static Type getRuntimeTypeIfMoreSpecific(Type type, Object value) { if (value != null && (type == Object.class || type instanceof TypeVariable || type instanceof Class)) { diff --git a/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java b/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java index 5a60ca63..c9c3e1ef 100644 --- a/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java +++ b/gson/src/test/java/com/google/gson/ObjectTypeAdapterTest.java @@ -27,6 +27,7 @@ public final class ObjectTypeAdapterTest extends TestCase { private final MiniGson gson = new MiniGson.Builder().build(); private final TypeAdapter adapter = gson.getAdapter(Object.class); + @SuppressWarnings("unchecked") public void testDeserialize() throws Exception { Map map = (Map) adapter.fromJson("{a: 5, b: [1, 2, null], c: {x: y}}"); assertEquals(5.0, map.get("a")); @@ -35,6 +36,7 @@ public final class ObjectTypeAdapterTest extends TestCase { assertEquals(3, map.size()); } + @SuppressWarnings("unused") public void testSerialize() throws Exception { Object object = new Object() { Object a = 5; 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 cf3a45cd..c3102e1a 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -208,6 +208,7 @@ public class CollectionTest extends TestCase { assertTrue(json.contains(bag1.getExpectedJson())); } + @SuppressWarnings("unchecked") public void testRawCollectionDeserializationNotAlllowed() { String json = "[0,1,2,3,4,5,6,7,8,9]"; Collection integers = gson.fromJson(json, Collection.class);