DATAMONGO-324 - Added shortcut in MappingMongoConverter to allow reading DBObjects without conversion.
Added check in MappingMongoConverter.read(…) to shortcut object conversion if the requested type is DBObject.
This commit is contained in:
@@ -182,6 +182,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
if (conversions.hasCustomReadTarget(dbo.getClass(), rawType)) {
|
||||
return conversionService.convert(dbo, rawType);
|
||||
}
|
||||
|
||||
if (DBObject.class.isAssignableFrom(rawType)) {
|
||||
return (S) dbo;
|
||||
}
|
||||
|
||||
if (typeToUse.isCollectionLike() && dbo instanceof BasicDBList) {
|
||||
return (S) readCollectionOrArray(typeToUse, (BasicDBList) dbo);
|
||||
|
||||
@@ -764,7 +764,7 @@ public class MappingMongoConverterUnitTests {
|
||||
* @see DATAMONGO-309
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void writesArraysAsMapValuesCorrectly() {
|
||||
|
||||
ClassWithMapProperty wrapper = new ClassWithMapProperty();
|
||||
@@ -786,6 +786,39 @@ public class MappingMongoConverterUnitTests {
|
||||
assertThat(list, hasItem((Object) "bar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-324
|
||||
*/
|
||||
@Test
|
||||
public void writesDbObjectCorrectly() {
|
||||
|
||||
DBObject dbObject = new BasicDBObject();
|
||||
dbObject.put("foo", "bar");
|
||||
|
||||
DBObject result = new BasicDBObject();
|
||||
|
||||
converter.write(dbObject, result);
|
||||
|
||||
result.removeField(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY);
|
||||
assertThat(dbObject, is(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-324
|
||||
*/
|
||||
@Test
|
||||
public void readsDbObjectCorrectly() {
|
||||
|
||||
DBObject dbObject = new BasicDBObject();
|
||||
dbObject.put("foo", "bar");
|
||||
|
||||
DBObject result = converter.read(DBObject.class, dbObject);
|
||||
|
||||
assertThat(result, is(dbObject));
|
||||
}
|
||||
|
||||
|
||||
|
||||
class GenericType<T> {
|
||||
T content;
|
||||
}
|
||||
@@ -817,6 +850,7 @@ public class MappingMongoConverterUnitTests {
|
||||
String city;
|
||||
}
|
||||
|
||||
|
||||
interface Contact {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user