DATAMONGO-2300 - Add check rawType is null in readMap.
Original Pull Request: #763
This commit is contained in:
committed by
Christoph Strobl
parent
6389055d3a
commit
ba8f28f623
@@ -90,6 +90,7 @@ import com.mongodb.DBRef;
|
||||
* @author Christoph Strobl
|
||||
* @author Jordi Llach
|
||||
* @author Mark Paluch
|
||||
* @author Heesu Jung
|
||||
*/
|
||||
public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware {
|
||||
|
||||
@@ -1170,7 +1171,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
map.put(key, read(defaultedValueType, (BasicDBObject) value, path));
|
||||
} else if (value instanceof DBRef) {
|
||||
map.put(key, DBRef.class.equals(rawValueType) ? value
|
||||
: readAndConvertDBRef((DBRef) value, defaultedValueType, ObjectPath.ROOT, rawValueType));
|
||||
: readAndConvertDBRef((DBRef) value, defaultedValueType, ObjectPath.ROOT, rawValueType != null ? rawValueType : ClassTypeInformation.OBJECT.getType()));
|
||||
} else if (value instanceof List) {
|
||||
map.put(key, readCollectionOrArray(valueType != null ? valueType : ClassTypeInformation.LIST,
|
||||
(List<Object>) value, path));
|
||||
|
||||
@@ -75,6 +75,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.data.mongodb.core.mapping.PersonPojoStringId;
|
||||
import org.springframework.data.mongodb.core.mapping.TextScore;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.mongodb.BasicDBList;
|
||||
@@ -88,6 +89,7 @@ import com.mongodb.DBRef;
|
||||
* @author Patrik Wasik
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Heesu Jung
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MappingMongoConverterUnitTests {
|
||||
@@ -2078,6 +2080,23 @@ public class MappingMongoConverterUnitTests {
|
||||
.isEqualTo(new BasicDBObject("property", "value"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2300
|
||||
public void readAndConvertDBRefNestedByMapCorrectly() {
|
||||
|
||||
org.bson.Document cluster = new org.bson.Document("_id", 100L);
|
||||
DBRef dbRef = new DBRef("clusters", 100L);
|
||||
|
||||
org.bson.Document data = new org.bson.Document("_id", 3L);
|
||||
data.append("cluster", dbRef);
|
||||
|
||||
MappingMongoConverter spyConverter = spy(converter);
|
||||
Mockito.doReturn(cluster).when(spyConverter).readRef(dbRef);
|
||||
|
||||
Map<Object, Object> result = spyConverter.readMap(ClassTypeInformation.MAP, data, ObjectPath.ROOT);
|
||||
|
||||
assertThat(((LinkedHashMap) result.get("cluster")).get("_id")).isEqualTo(100L);
|
||||
}
|
||||
|
||||
static class GenericType<T> {
|
||||
T content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user