DATAMONGO-2300 - Add check rawType is null in readMap.
Original Pull Request: #763
This commit is contained in:
committed by
Christoph Strobl
parent
e9c9938016
commit
7a7f7c942d
@@ -94,6 +94,7 @@ import com.mongodb.DBRef;
|
||||
* @author Jordi Llach
|
||||
* @author Mark Paluch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Heesu Jung
|
||||
*/
|
||||
public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware {
|
||||
|
||||
@@ -1191,7 +1192,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));
|
||||
|
||||
@@ -80,6 +80,7 @@ import org.springframework.data.mongodb.core.mapping.PersonPojoStringId;
|
||||
import org.springframework.data.mongodb.core.mapping.TextScore;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AfterConvertCallback;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.mongodb.BasicDBList;
|
||||
@@ -95,6 +96,7 @@ import com.mongodb.DBRef;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Heesu Jung
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MappingMongoConverterUnitTests {
|
||||
@@ -2159,11 +2161,28 @@ public class MappingMongoConverterUnitTests {
|
||||
org.bson.Document document = new org.bson.Document("personMap", refMap);
|
||||
|
||||
DBRefWrapper result = converter.read(DBRefWrapper.class, document);
|
||||
|
||||
|
||||
verify(afterConvertCallback).onAfterConvert(eq(result.personMap.get("foo")),
|
||||
eq(new org.bson.Document()), any());
|
||||
}
|
||||
|
||||
@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