DATAMONGO-2011 - Relax type check when mapping collections.
Original pull request: #587.
This commit is contained in:
committed by
Oliver Gierke
parent
6f011b0fa1
commit
4d309bd7f0
@@ -980,13 +980,12 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
items.add(read(componentType, (BasicDBObject) element, path));
|
||||
} else {
|
||||
|
||||
if (element instanceof Collection) {
|
||||
if (!Object.class.equals(rawComponentType) && element instanceof Collection) {
|
||||
if (!rawComponentType.isArray() && !ClassUtils.isAssignable(Iterable.class, rawComponentType)) {
|
||||
throw new MappingException(
|
||||
String.format(INCOMPATIBLE_TYPES, element, element.getClass(), rawComponentType, path));
|
||||
}
|
||||
}
|
||||
|
||||
if (element instanceof List) {
|
||||
items.add(readCollectionOrArray(componentType, (Collection<Object>) element, path));
|
||||
} else {
|
||||
|
||||
@@ -1886,6 +1886,15 @@ public class MappingMongoConverterUnitTests {
|
||||
assertThat(result.nestedFloats).isEqualTo(new float[][][] { { { 1.0f, 2.0f } } });
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2011
|
||||
public void readsNestedListsToObjectCorrectly() {
|
||||
|
||||
List<String> values = Arrays.asList("ONE", "TWO");
|
||||
org.bson.Document source = new org.bson.Document("value", Collections.singletonList(values));
|
||||
|
||||
assertThat(converter.read(Attribute.class, source).value).isInstanceOf(List.class);
|
||||
}
|
||||
|
||||
static class GenericType<T> {
|
||||
T content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user