Skip to content

Commit ba291e8

Browse files
DATAMONGO-2011 - Relax type check when mapping collections.
1 parent af0e795 commit ba291e8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -982,13 +982,12 @@ private Object readCollectionOrArray(TypeInformation<?> targetType, Collection<?
982982
items.add(read(componentType, (BasicDBObject) element, path));
983983
} else {
984984

985-
if (element instanceof Collection) {
985+
if (!Object.class.equals(rawComponentType) && element instanceof Collection) {
986986
if (!rawComponentType.isArray() && !ClassUtils.isAssignable(Iterable.class, rawComponentType)) {
987987
throw new MappingException(
988988
String.format(INCOMPATIBLE_TYPES, element, element.getClass(), rawComponentType, path));
989989
}
990990
}
991-
992991
if (element instanceof List) {
993992
items.add(readCollectionOrArray(componentType, (Collection<Object>) element, path));
994993
} else {

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,15 @@ public void readsImmutableObjectCorrectly() {
18831883
assertThat(result.witherUsed).isTrue();
18841884
}
18851885

1886+
@Test // DATAMONGO-2011
1887+
public void readsNestedListsToObjectCorrectly() {
1888+
1889+
List<String> values = Arrays.asList("ONE", "TWO");
1890+
org.bson.Document source = new org.bson.Document("value", Collections.singletonList(values));
1891+
1892+
assertThat(converter.read(Attribute.class, source).value).isInstanceOf(List.class);
1893+
}
1894+
18861895
static class GenericType<T> {
18871896
T content;
18881897
}

0 commit comments

Comments
 (0)