Fix update mapping using nested integer keys on map structures.
Closes: #3775 Original Pull Request: #3815
This commit is contained in:
committed by
Christoph Strobl
parent
2cbed2a052
commit
852a461429
@@ -69,6 +69,7 @@ import com.mongodb.DBRef;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author David Julia
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
public class QueryMapper {
|
||||
|
||||
@@ -1026,8 +1027,8 @@ public class QueryMapper {
|
||||
*/
|
||||
protected static class MetadataBackedField extends Field {
|
||||
|
||||
private static final Pattern POSITIONAL_PARAMETER_PATTERN = Pattern.compile("\\.\\$(\\[.*?\\])?|\\.\\d+");
|
||||
private static final Pattern DOT_POSITIONAL_PATTERN = Pattern.compile("\\.\\d+");
|
||||
private static final Pattern POSITIONAL_PARAMETER_PATTERN = Pattern.compile("\\.\\$(\\[.*?\\])?");
|
||||
private static final Pattern DOT_POSITIONAL_PATTERN = Pattern.compile("\\.\\d+(?!$)");
|
||||
private static final String INVALID_ASSOCIATION_REFERENCE = "Invalid path reference %s! Associations can only be pointed to directly or via their id property!";
|
||||
|
||||
private final MongoPersistentEntity<?> entity;
|
||||
|
||||
@@ -59,6 +59,7 @@ import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.TextQuery;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
@@ -1326,6 +1327,25 @@ public class QueryMapperUnitTests {
|
||||
org.bson.Document mappedFields = mapper.getMappedFields(new org.bson.Document("id", 1), context.getPersistentEntity(WithStringId.class));
|
||||
assertThat(mappedFields).containsEntry("_id", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapNestedStringFieldCorrectly() {
|
||||
Update update = new Update();
|
||||
update.set("levelOne.a.b.d", "e");
|
||||
org.bson.Document document = mapper.getMappedObject(update.getUpdateObject(),
|
||||
context.getPersistentEntity(EntityWithNestedMap.class));
|
||||
assertThat(document).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.a.b.d","e")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapNestedIntegerFieldCorrectly() {
|
||||
Update update = new Update();
|
||||
update.set("levelOne.0.1.3", "4");
|
||||
org.bson.Document document = mapper.getMappedObject(update.getUpdateObject(),
|
||||
context.getPersistentEntity(EntityWithNestedMap.class));
|
||||
assertThat(document).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.3","4")));
|
||||
}
|
||||
|
||||
|
||||
@Test // GH-3783
|
||||
void retainsId$InWithStringArray() {
|
||||
@@ -1514,6 +1534,11 @@ public class QueryMapperUnitTests {
|
||||
static class EntityWithComplexValueTypeList {
|
||||
List<SimpleEntityWithoutId> list;
|
||||
}
|
||||
|
||||
static class EntityWithNestedMap {
|
||||
Map<String, Map<String, Map<String, Object>>> levelOne;
|
||||
}
|
||||
|
||||
|
||||
static class WithExplicitTargetTypes {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user