DATAMONGO-2011 - Relax type check when mapping collections.
Original pull request: #587.
This commit is contained in:
committed by
Oliver Gierke
parent
648bfdfc67
commit
088928c64a
@@ -1002,13 +1002,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 {
|
||||
|
||||
@@ -1895,6 +1895,15 @@ public class MappingMongoConverterUnitTests {
|
||||
assertThat(target.value).isEqualTo("data");
|
||||
}
|
||||
|
||||
@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