DATAMONGO-508 - Eagerly return DBRef creation if the given value already is a DBRef.
This commit is contained in:
@@ -671,6 +671,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
Assert.notNull(target);
|
Assert.notNull(target);
|
||||||
|
|
||||||
|
if (target instanceof DBRef) {
|
||||||
|
return (DBRef) target;
|
||||||
|
}
|
||||||
|
|
||||||
MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass());
|
MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass());
|
||||||
|
|
||||||
if (null == targetEntity) {
|
if (null == targetEntity) {
|
||||||
|
|||||||
@@ -1278,6 +1278,20 @@ public class MappingMongoConverterUnitTests {
|
|||||||
fail(String.format("Didn't find synthetic field on %s!", target));
|
fail(String.format("Didn't find synthetic field on %s!", target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAMGONGO-508
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void eagerlyReturnsDBRefObjectIfTargetAlreadyIsOne() {
|
||||||
|
|
||||||
|
DB db = mock(DB.class);
|
||||||
|
DBRef dbRef = new DBRef(db, "collection", "id");
|
||||||
|
|
||||||
|
org.springframework.data.mongodb.core.mapping.DBRef annotation = mock(org.springframework.data.mongodb.core.mapping.DBRef.class);
|
||||||
|
|
||||||
|
assertThat(converter.createDBRef(dbRef, annotation), is(dbRef));
|
||||||
|
}
|
||||||
|
|
||||||
static class GenericType<T> {
|
static class GenericType<T> {
|
||||||
T content;
|
T content;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user