Skip to content

Commit 0ce067c

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-1809 - Fix positional parameter detection for PropertyPaths.
We now make sure to capture all digits for positional parameters. Original pull request: spring-projects#508.
1 parent 2974cce commit 0ce067c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ private PersistentPropertyPath<MongoPersistentProperty> getPath(String pathExpre
930930

931931
try {
932932

933-
PropertyPath path = PropertyPath.from(pathExpression.replaceAll("\\.\\d", ""), entity.getTypeInformation());
933+
PropertyPath path = PropertyPath.from(pathExpression.replaceAll("\\.\\d+", ""), entity.getTypeInformation());
934934
PersistentPropertyPath<MongoPersistentProperty> propertyPath = mappingContext.getPersistentPropertyPath(path);
935935

936936
Iterator<MongoPersistentProperty> iterator = propertyPath.iterator();

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import static org.springframework.data.mongodb.core.DocumentTestUtils.*;
2222
import static org.springframework.data.mongodb.test.util.IsBsonObject.*;
2323

24+
import lombok.AllArgsConstructor;
25+
import lombok.NoArgsConstructor;
26+
2427
import java.time.LocalDate;
2528
import java.util.Arrays;
2629
import java.util.Collections;
@@ -677,6 +680,23 @@ public void mappingShouldRetainTypeInformationOfNestedListWhenUpdatingConcreteyP
677680
.containing("$set.concreteTypeWithListAttributeOfInterfaceType.models.[0]._class", ModelImpl.class.getName()));
678681
}
679682

683+
@Test // DATAMONGO-1809
684+
public void pathShouldIdentifyPositionalParameterWithMoreThanOneDigit() {
685+
686+
Document at2digitPosition = mapper.getMappedObject(new Update()
687+
.addToSet("concreteInnerList.10.concreteTypeList", new SomeInterfaceImpl("szeth")).getUpdateObject(),
688+
context.getPersistentEntity(Outer.class));
689+
690+
Document at3digitPosition = mapper.getMappedObject(new Update()
691+
.addToSet("concreteInnerList.123.concreteTypeList", new SomeInterfaceImpl("lopen")).getUpdateObject(),
692+
context.getPersistentEntity(Outer.class));
693+
694+
assertThat(at2digitPosition, is(equalTo(new Document("$addToSet",
695+
new Document("concreteInnerList.10.concreteTypeList", new Document("value", "szeth"))))));
696+
assertThat(at3digitPosition, is(equalTo(new Document("$addToSet",
697+
new Document("concreteInnerList.123.concreteTypeList", new Document("value", "lopen"))))));
698+
}
699+
680700
@Test // DATAMONGO-1236
681701
public void mappingShouldRetainTypeInformationForObjectValues() {
682702

@@ -1254,6 +1274,7 @@ static class Outer {
12541274
static class ConcreteInner {
12551275
List<SomeInterfaceType> interfaceTypeList;
12561276
List<SomeAbstractType> abstractTypeList;
1277+
List<SomeInterfaceImpl> concreteTypeList;
12571278
}
12581279

12591280
interface SomeInterfaceType {
@@ -1264,8 +1285,11 @@ static abstract class SomeAbstractType {
12641285

12651286
}
12661287

1288+
@AllArgsConstructor
1289+
@NoArgsConstructor
12671290
static class SomeInterfaceImpl extends SomeAbstractType implements SomeInterfaceType {
12681291

1292+
String value;
12691293
}
12701294

12711295
}

0 commit comments

Comments
 (0)