Skip to content

Commit 029065f

Browse files
Fixes it but needs a better concept
1 parent e99caf7 commit 029065f

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -1470,11 +1470,15 @@ protected String mapPropertyName(MongoPersistentProperty property) {
14701470
return mappedName.toString();
14711471
}
14721472

1473-
String nextToken = nextToken();
1474-
if (isPositionalParameter(nextToken)) {
1475-
1476-
mappedName.append(".").append(nextToken);
1477-
currentIndex += 2;
1473+
int i = 1;
1474+
String nextToken = pathParts.get(currentIndex + i);
1475+
if(isPositionalParameter(nextToken)) {
1476+
while (isPositionalParameter(nextToken)) {
1477+
mappedName.append(".").append(nextToken);
1478+
i++;
1479+
nextToken = currentIndex + i < pathParts.size() ? pathParts.get(currentIndex + i) : "";
1480+
}
1481+
currentIndex += i;
14781482
return mappedName.toString();
14791483
}
14801484

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

+19
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,17 @@ void updateConsidersValueConverterWhenPresent() {
13501350
assertThat(mappedUpdate).isEqualTo("{ $set : { 'text' : 'eulav' } }");
13511351
}
13521352

1353+
@ParameterizedTest // GH-4502
1354+
@ValueSource(strings = {"levelOne.levelTwo.1", "levelOne.levelTwo.1.0", "levelOne.levelTwo.2.0",})
1355+
void objectNestedIntegerFieldCorrectly(String path) {
1356+
1357+
Update update = new Update().set(path, "4");
1358+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1359+
context.getPersistentEntity(EntityWithNestedObject1.class));
1360+
1361+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document(path, "4")));
1362+
}
1363+
13531364
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
13541365
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
13551366
}
@@ -1818,4 +1829,12 @@ static class WithPropertyValueConverter {
18181829
@ValueConverter(ReversingValueConverter.class)
18191830
String text;
18201831
}
1832+
1833+
static class EntityWithNestedObject1 {
1834+
EntityWithNestedObject2 levelOne;
1835+
}
1836+
1837+
static class EntityWithNestedObject2 {
1838+
Integer levelTwo;
1839+
}
18211840
}

0 commit comments

Comments
 (0)