Skip to content

Commit 071f293

Browse files
committed
DATAMONGO-369 - Fixed query mapping when a DBObject is included in the query object.
Replaced premature return with continue to break the for loop appropriately.
1 parent d2a18e9 commit 071f293

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/QueryMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public DBObject getMappedObject(DBObject query, MongoPersistentEntity<?> entity)
100100
value = convertId(value);
101101
} else if (value instanceof DBObject) {
102102
newDbo.put(newKey, getMappedObject((DBObject) value, entity));
103-
return newDbo;
103+
continue;
104104
}
105105

106106
newDbo.put(newKey, converter.convertToMongoType(value));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryMapperUnitTests.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.mockito.runners.MockitoJUnitRunner;
3232
import org.springframework.data.annotation.Id;
3333
import org.springframework.data.mongodb.MongoDbFactory;
34+
import org.springframework.data.mongodb.core.Person;
3435
import org.springframework.data.mongodb.core.QueryMapper;
3536
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
3637
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
@@ -172,14 +173,28 @@ public void handlesNativelyBuiltQueryCorrectly() {
172173
mapper.getMappedObject(query, null);
173174
}
174175

176+
/**
177+
* @see DATAMONGO-369
178+
*/
179+
@Test
180+
public void handlesAllPropertiesIfDBObject() {
181+
182+
DBObject query = new BasicDBObject();
183+
query.put("foo", new BasicDBObject("$in", Arrays.asList(1, 2)));
184+
query.put("bar", new Person());
185+
186+
DBObject result = mapper.getMappedObject(query, null);
187+
assertThat(result.get("bar"), is(notNullValue()));
188+
}
189+
175190
class Sample {
176-
191+
177192
@Id
178193
private String foo;
179194
}
180-
195+
181196
class BigIntegerId {
182-
197+
183198
@Id
184199
private BigInteger id;
185200
}

0 commit comments

Comments
 (0)