DATAMONGO-2410 - Fix Document to BasicDBObject conversion.
Original pull request: #813.
This commit is contained in:
committed by
Mark Paluch
parent
dbf43941be
commit
c5b892f03b
@@ -239,12 +239,21 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return conversionService.convert(bson, rawType);
|
||||
}
|
||||
|
||||
if (DBObject.class.isAssignableFrom(rawType)) {
|
||||
if (Document.class.isAssignableFrom(rawType)) {
|
||||
return (S) bson;
|
||||
}
|
||||
|
||||
if (Document.class.isAssignableFrom(rawType)) {
|
||||
return (S) bson;
|
||||
if (DBObject.class.isAssignableFrom(rawType)) {
|
||||
|
||||
if (bson instanceof DBObject) {
|
||||
return (S) bson;
|
||||
}
|
||||
|
||||
if (bson instanceof Document) {
|
||||
return (S) new BasicDBObject((Document) bson);
|
||||
}
|
||||
|
||||
return (S) DBObject.class.cast(bson);
|
||||
}
|
||||
|
||||
if (typeToUse.isCollectionLike() && bson instanceof List) {
|
||||
@@ -273,9 +282,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
if (codecRegistryProvider != null) {
|
||||
|
||||
Optional<? extends Codec<? extends S>> codec = codecRegistryProvider.getCodecFor(rawType);
|
||||
if(codec.isPresent()) {
|
||||
return codec.get().decode(new JsonReader(target.toJson()),
|
||||
DecoderContext.builder().build());
|
||||
if (codec.isPresent()) {
|
||||
return codec.get().decode(new JsonReader(target.toJson()), DecoderContext.builder().build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.mongodb.BasicDBList;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBRef;
|
||||
|
||||
/**
|
||||
@@ -2067,6 +2068,13 @@ public class MappingMongoConverterUnitTests {
|
||||
assertThat(target.dateAsObjectId).isEqualTo(new Date(reference.getTimestamp()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2410
|
||||
public void shouldAllowReadingBackDbObject() {
|
||||
|
||||
assertThat(converter.read(BasicDBObject.class, new org.bson.Document("property", "value")))
|
||||
.isEqualTo(new BasicDBObject("property", "value"));
|
||||
}
|
||||
|
||||
static class GenericType<T> {
|
||||
T content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user