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>
|
<downloadSources>true</downloadSources>
|
||||||
<downloadJavadocs>true</downloadJavadocs>
|
<downloadJavadocs>true</downloadJavadocs>
|
||||||
<workspace>
|
<workspace>
|
||||||
../eclipse-ws/
|
/Users/jleitch/eclipse/workspace/
|
||||||
</workspace>
|
</workspace>
|
||||||
<workspaceCodeStylesURL>
|
<workspaceCodeStylesURL>
|
||||||
file:///${basedir}/../lib/gson-formatting-styles.xml
|
file:///${basedir}/../lib/gson-formatting-styles.xml
|
||||||
|
@ -382,8 +382,8 @@ final class DefaultTypeAdapters {
|
|||||||
childGenericType = new TypeInfoCollection(typeOfSrc).getElementType();
|
childGenericType = new TypeInfoCollection(typeOfSrc).getElementType();
|
||||||
}
|
}
|
||||||
for (Object child : src) {
|
for (Object child : src) {
|
||||||
Type childType = (childGenericType == null) ?
|
Type childType = (childGenericType == null || childGenericType == Object.class)
|
||||||
childType = child.getClass() : childGenericType;
|
? child.getClass() : childGenericType;
|
||||||
JsonElement element = context.serialize(child, childType);
|
JsonElement element = context.serialize(child, childType);
|
||||||
array.add(element);
|
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() {
|
public void testCollectionOfStringsSerialization() {
|
||||||
List<String> target = new ArrayList<String>();
|
List<String> target = new ArrayList<String>();
|
||||||
target.add("Hello");
|
target.add("Hello");
|
||||||
|
Loading…
Reference in New Issue
Block a user