diff --git a/gson/pom.xml b/gson/pom.xml index 0096988d..4895b33a 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -111,7 +111,7 @@ true true - ../eclipse-ws/ + /Users/jleitch/eclipse/workspace/ file:///${basedir}/../lib/gson-formatting-styles.xml diff --git a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java index 8249ff63..17ba400b 100644 --- a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java +++ b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java @@ -382,8 +382,8 @@ final class DefaultTypeAdapters { childGenericType = new TypeInfoCollection(typeOfSrc).getElementType(); } for (Object child : src) { - Type childType = (childGenericType == null) ? - childType = child.getClass() : childGenericType; + Type childType = (childGenericType == null || childGenericType == Object.class) + ? child.getClass() : childGenericType; JsonElement element = context.serialize(child, childType); array.add(element); } 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 c2573bb1..05ee8ccc 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -142,6 +142,16 @@ public class CollectionTest extends TestCase { } } + public void testCollectionOfObjectSerialization() { + List target = new ArrayList(); + target.add("Hello"); + target.add("World"); + assertEquals("[\"Hello\",\"World\"]", gson.toJson(target)); + + Type type = new TypeToken>() {}.getType(); + assertEquals("[\"Hello\",\"World\"]", gson.toJson(target, type)); + } + public void testCollectionOfStringsSerialization() { List target = new ArrayList(); target.add("Hello");