Allow serialization of Object in collections. This used to be supported before restructuring the Collection type handling.
This commit is contained in:
parent
3df2d44e40
commit
2250afe825
@ -111,7 +111,7 @@
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
<workspace>
|
||||
../eclipse-ws/
|
||||
/Users/jleitch/eclipse/workspace/
|
||||
</workspace>
|
||||
<workspaceCodeStylesURL>
|
||||
file:///${basedir}/../lib/gson-formatting-styles.xml
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -142,6 +142,16 @@ public class CollectionTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testCollectionOfObjectSerialization() {
|
||||
List<Object> target = new ArrayList<Object>();
|
||||
target.add("Hello");
|
||||
target.add("World");
|
||||
assertEquals("[\"Hello\",\"World\"]", gson.toJson(target));
|
||||
|
||||
Type type = new TypeToken<List<Object>>() {}.getType();
|
||||
assertEquals("[\"Hello\",\"World\"]", gson.toJson(target, type));
|
||||
}
|
||||
|
||||
public void testCollectionOfStringsSerialization() {
|
||||
List<String> target = new ArrayList<String>();
|
||||
target.add("Hello");
|
||||
|
Loading…
Reference in New Issue
Block a user